Skip to content

Commit

Permalink
Fix bad access after routing, caused by accessing a Map which has been
Browse files Browse the repository at this point in the history
reset.
  • Loading branch information
mmichalek committed Nov 10, 2015
1 parent 898147d commit 0dd6d10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
13 changes: 13 additions & 0 deletions symmetric-client-clib-test/src/util/MapTest.c
Expand Up @@ -302,6 +302,18 @@ void SymMapTest_testRemove() {
map->remove(map, "1");
}

void SymMapTest_testResetRemove() {
int mapSize = 16;
SymMap *map = SymMap_new(NULL, mapSize);
int i;
for (i = 0; i < mapSize; i++) {
map->put(map, SymStringUtils_format("%d", i), SymStringUtils_format("value %d", i));
}

map->reset(map);
map->remove(map, "1");
}

int SymMapTest_CUnit() {
CU_pSuite suite = CU_add_suite("SymMapTest", NULL, NULL);
if (suite == NULL) {
Expand All @@ -321,6 +333,7 @@ int SymMapTest_CUnit() {
CU_add_test(suite, "SymMapTest_testKeysSingleValue", SymMapTest_testKeysSingleValue) == NULL ||
CU_add_test(suite, "SymMapTest_testKeysMultiValue", SymMapTest_testKeysMultiValue) == NULL ||
CU_add_test(suite, "SymMapTest_testRemove", SymMapTest_testRemove) == NULL ||
CU_add_test(suite, "SymMapTest_testResetRemove", SymMapTest_testResetRemove) == NULL ||
1==0

) {
Expand Down
21 changes: 0 additions & 21 deletions symmetric-client-clib/src/model/TriggerHistory.c
Expand Up @@ -62,30 +62,9 @@ char * SymTriggerHistory_getTriggerNameForDmlType(SymTriggerHistory *this, SymDa
}

void SymTriggerHistory_destroy(SymTriggerHistory *this) {
// Being selective here based on Valgrind reports and testing that
// shows other fields are static memory or really owned by someone else.
if (this->sourceTableName) {
// free(this->sourceTableName);
}
if (this->nameForInsertTrigger) {
free(this->nameForInsertTrigger);
}
if (this->nameForUpdateTrigger) {
free(this->nameForUpdateTrigger);
}
if (this->nameForDeleteTrigger) {
free(this->nameForDeleteTrigger);
}

if (this->createTime) {
this->createTime->destroy(this->createTime);
}
if (this->columnNames) {
free(this->columnNames);
}
if (this->pkColumnNames) {
free(this->pkColumnNames);
}
if (this->inactiveTime) {
this->inactiveTime->destroy(this->inactiveTime);
}
Expand Down
5 changes: 5 additions & 0 deletions symmetric-client-clib/src/util/Map.c
Expand Up @@ -199,6 +199,11 @@ void SymMap_resetAll(SymMap *this, void (*destroyObject)(void *object)) {
}
index++;
}

int i;
for (i = 0; i < this->size; i++) {
this->table[i] = NULL;
}
}

void SymMap_reset(SymMap *this) {
Expand Down

0 comments on commit 0dd6d10

Please sign in to comment.