X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=assoc.c;h=4561de4247530f9f6d08d3ec7c6406a3b24b66a0;hb=47a7673055e4f82ee6c803df04eb1e2a87e717b7;hp=476facb340dcd3f429f3669220dea10d6036076a;hpb=3185942a5234e26ab13fa02f9c51d340cec514f8;p=platform%2Fupstream%2Fbash.git diff --git a/assoc.c b/assoc.c index 476facb..4561de4 100644 --- a/assoc.c +++ b/assoc.c @@ -77,6 +77,11 @@ assoc_insert (hash, key, value) b = hash_search (key, hash, HASH_CREATE); if (b == 0) return -1; + /* If we are overwriting an existing element's value, we're not going to + use the key. Nothing in the array assignment code path frees the key + string, so we can free it here to avoid a memory leak. */ + if (b->key != key) + free (key); FREE (b->data); b->data = value ? savestring (value) : (char *)0; return (0); @@ -405,7 +410,14 @@ assoc_to_assign (hash, quoted) for (i = 0; i < hash->nbuckets; i++) for (tlist = hash_items (i, hash); tlist; tlist = tlist->next) { +#if 1 + if (sh_contains_shell_metas (tlist->key)) + istr = sh_double_quote (tlist->key); + else + istr = tlist->key; +#else istr = tlist->key; +#endif vstr = tlist->data ? sh_double_quote ((char *)tlist->data) : (char *)0; elen = STRLEN (istr) + 8 + STRLEN (vstr); @@ -423,6 +435,10 @@ assoc_to_assign (hash, quoted) } ret[rlen++] = ' '; + + if (istr != tlist->key) + FREE (istr); + FREE (vstr); }