diff options
author | 2019-10-22 08:39:07 +0000 | |
---|---|---|
committer | 2019-10-22 08:39:07 +0000 | |
commit | 49b9891dc32ea1fbd0af4711a200b425c7482da0 (patch) | |
tree | e37278b40e550d644d57f081345ee9c70bae0e57 /hicn-light | |
parent | 878cd692abbc5f65d605fa6faeb530368152ec80 (diff) | |
parent | b35f1ceb2b3c32eedbe0392201a5fc174bd43343 (diff) |
Merge "[HICN-344] Memory management issues in symbolic table causes double free"
Diffstat (limited to 'hicn-light')
-rw-r--r-- | hicn-light/src/hicn/config/symbolicNameTable.c | 38 |
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; |