Unverified Commit 1c7eb0ad authored by Binbin's avatar Binbin Committed by GitHub
Browse files

Fix minor memory leaks in dictTest (#12962)

Introduced in #12952, reported by valgrind.
parent 0e5a4a27
...@@ -1807,7 +1807,9 @@ int dictTest(int argc, char **argv, int flags) { ...@@ -1807,7 +1807,9 @@ int dictTest(int argc, char **argv, int flags) {
/* Delete keys until 13 keys remain, now is 13:128, so we can /* Delete keys until 13 keys remain, now is 13:128, so we can
* satisfy HASHTABLE_MIN_FILL in the next test. */ * satisfy HASHTABLE_MIN_FILL in the next test. */
for (j = 0; j < 68; j++) { for (j = 0; j < 68; j++) {
retval = dictDelete(dict,stringFromLongLong(j)); char *key = stringFromLongLong(j);
retval = dictDelete(dict, key);
zfree(key);
assert(retval == DICT_OK); assert(retval == DICT_OK);
} }
assert(dictSize(dict) == 13); assert(dictSize(dict) == 13);
...@@ -1817,7 +1819,9 @@ int dictTest(int argc, char **argv, int flags) { ...@@ -1817,7 +1819,9 @@ int dictTest(int argc, char **argv, int flags) {
} }
TEST("Delete one more key, trigger the dict resize") { TEST("Delete one more key, trigger the dict resize") {
retval = dictDelete(dict,stringFromLongLong(68)); char *key = stringFromLongLong(68);
retval = dictDelete(dict, key);
zfree(key);
assert(retval == DICT_OK); assert(retval == DICT_OK);
assert(dictSize(dict) == 12); assert(dictSize(dict) == 12);
assert(DICTHT_SIZE(dict->ht_size_exp[0]) == 128); assert(DICTHT_SIZE(dict->ht_size_exp[0]) == 128);
...@@ -1849,7 +1853,9 @@ int dictTest(int argc, char **argv, int flags) { ...@@ -1849,7 +1853,9 @@ int dictTest(int argc, char **argv, int flags) {
* HASHTABLE_MIN_FILL / dict_force_resize_ratio. */ * HASHTABLE_MIN_FILL / dict_force_resize_ratio. */
dictSetResizeEnabled(DICT_RESIZE_AVOID); dictSetResizeEnabled(DICT_RESIZE_AVOID);
for (j = 0; j < 125; j++) { for (j = 0; j < 125; j++) {
retval = dictDelete(dict,stringFromLongLong(j)); char *key = stringFromLongLong(j);
retval = dictDelete(dict, key);
zfree(key);
assert(retval == DICT_OK); assert(retval == DICT_OK);
} }
assert(dictSize(dict) == 3); assert(dictSize(dict) == 3);
...@@ -1857,7 +1863,9 @@ int dictTest(int argc, char **argv, int flags) { ...@@ -1857,7 +1863,9 @@ int dictTest(int argc, char **argv, int flags) {
} }
TEST("Delete one more key, trigger the dict resize") { TEST("Delete one more key, trigger the dict resize") {
retval = dictDelete(dict,stringFromLongLong(125)); char *key = stringFromLongLong(125);
retval = dictDelete(dict, key);
zfree(key);
assert(retval == DICT_OK); assert(retval == DICT_OK);
assert(dictSize(dict) == 2); assert(dictSize(dict) == 2);
assert(DICTHT_SIZE(dict->ht_size_exp[0]) == 128); assert(DICTHT_SIZE(dict->ht_size_exp[0]) == 128);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment