From 128237168042ed96818723414b3ba7f74af4a622 Mon Sep 17 00:00:00 2001 From: Jordan Bancino Date: Fri, 6 Jan 2023 18:50:31 +0000 Subject: [PATCH] Fix "bad pointer" warnings. --- src/Db.c | 2 +- src/Json.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Db.c b/src/Db.c index ffdb51d..4255dfb 100644 --- a/src/Db.c +++ b/src/Db.c @@ -511,7 +511,7 @@ DbLockFromArr(Db * db, Array * args) } ref->name = name; - HashMapSet(db->cache, hash, ref); + HashMapSet(db->cache, UtilStringDuplicate(hash), ref); db->cacheSize += ref->size; ref->next = NULL; diff --git a/src/Json.c b/src/Json.c index d96b89a..fa4295e 100644 --- a/src/Json.c +++ b/src/Json.c @@ -645,7 +645,18 @@ JsonFree(HashMap * object) while (HashMapIterate(object, &key, (void **) &value)) { - Free(key); + /* + * The key might not always be on the heap. In cases + * where the JSON object is built programmatically instead + * of with the parser, stack strings will probably have been + * used as the key. + */ + MemoryInfo *i = MemoryInfoGet(key); + if (i) + { + Free(key); + } + JsonValueFree(value); }