From 095f2fe731bfa0d941f505614a3aad223e846a19 Mon Sep 17 00:00:00 2001 From: borutr Date: Sun, 30 Mar 2003 19:47:08 +0000 Subject: [PATCH] deallocates the item, if allready exsists, before adding the new one git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2442 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCChasht.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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 * -- 2.30.2