aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-10-22 10:19:17 +0200
committerJordan Augé <jordan.auge+fdio@cisco.com>2019-10-22 10:19:17 +0200
commitb35f1ceb2b3c32eedbe0392201a5fc174bd43343 (patch)
treec26cd64862bfcb777e43ace729c287040a353708 /hicn-light/src
parentdceeb2d03626246a15b86354ac3e137ae4a3398f (diff)
[HICN-344] Memory management issues in symbolic table causes double free
Change-Id: Ia93f4068f4b4646e15397a8400bde3593e8de620 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com>
Diffstat (limited to 'hicn-light/src')
-rw-r--r--hicn-light/src/hicn/config/symbolicNameTable.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/hicn-light/src/hicn/config/symbolicNameTable.c b/hicn-light/src/hicn/config/symbolicNameTable.c
index 746c4e647..723039fae 100644
--- a/hicn-light/src/hicn/config/symbolicNameTable.c
+++ b/hicn-light/src/hicn/config/symbolicNameTable.c
@@ -127,19 +127,36 @@ bool symbolicNameTable_Add(SymbolicNameTable *table, const char *symbolicName,
parcAssertTrue(connid < UINT32_MAX, "Parameter connid must be less than %u",
UINT32_MAX);
- char *key = _createKey(symbolicName);
+ char *key1 = _createKey(symbolicName);
- uint32_t *value = parcMemory_Allocate(sizeof(uint32_t));
- *value = connid;
+ uint32_t *value1 = parcMemory_Allocate(sizeof(uint32_t));
+ *value1 = connid;
- bool success = parcHashCodeTable_Add(table->symbolicNameTable, key, value);
- success = parcHashCodeTable_Add(table->indexToNameTable, value, key);
- if (!success) {
- parcMemory_Deallocate((void **)&key);
- parcMemory_Deallocate((void **)&value);
- }
+ bool success = parcHashCodeTable_Add(table->symbolicNameTable, key1, value1);
+ if (!success)
+ goto ERR_NAME;
+
+ char *key2 = _createKey(symbolicName);
+
+ uint32_t *value2 = parcMemory_Allocate(sizeof(uint32_t));
+ *value2 = connid;
+ success = parcHashCodeTable_Add(table->indexToNameTable, value2, key2);
+ if (!success)
+ goto ERR_INDEX;
+
+ goto END;
+
+ERR_INDEX:
+ parcMemory_Deallocate((void **)&key2);
+ parcMemory_Deallocate((void **)&value2);
+ parcHashCodeTable_Del(table->symbolicNameTable, key1);
+ERR_NAME:
+ parcMemory_Deallocate((void **)&key1);
+ parcMemory_Deallocate((void **)&value1);
+END:
return success;
+
}
unsigned symbolicNameTable_Get(SymbolicNameTable *table,
@@ -152,9 +169,8 @@ unsigned symbolicNameTable_Get(SymbolicNameTable *table,
char *key = _createKey(symbolicName);
uint32_t *value = parcHashCodeTable_Get(table->symbolicNameTable, key);
- if (value) {
+ if (value)
connid = *value;
- }
parcMemory_Deallocate((void **)&key);
return connid;