X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCChasht.c;h=dd6322d451c632b5a70231f1ed0f57b6f979e628;hb=3bd25d75bcad68055bb616dcc29dde8a2965965e;hp=07aa2ec50f49c799f62200e5ae8a80b61beb9071;hpb=d0e08654a8100006948e3260646b7517060c5f9c;p=fw%2Fsdcc diff --git a/src/SDCChasht.c b/src/SDCChasht.c index 07aa2ec5..dd6322d4 100644 --- a/src/SDCChasht.c +++ b/src/SDCChasht.c @@ -561,11 +561,21 @@ _hash (const char *sz) void shash_add (hTab ** h, const char *szKey, const char *szValue) { + char *val; int key = _hash (szKey); - /* First, delete any that currently exist */ - hTabDeleteByKey (h, key, szKey, _compare); + + /* Find value of the item */ + val = (char *)hTabFindByKey(*h, key, szKey, _compare); + /* Delete any that currently exist */ + hTabDeleteByKey(h, key, szKey, _compare); + /* Deallocate old value in not NULL */ + if (val != NULL) + Safe_free(val); + /* Duplicate new value if not NULL */ + if (szValue != NULL) + szValue = Safe_strdup(szValue); /* Now add in ours */ - hTabAddItemLong (h, key, Safe_strdup (szKey), Safe_strdup (szValue)); + hTabAddItemLong (h, key, Safe_strdup (szKey), (void *)szValue); } const char *