diff options
author | john haque <j.eh@mchsi.com> | 2012-04-17 13:29:32 -0500 |
---|---|---|
committer | john haque <j.eh@mchsi.com> | 2012-04-17 13:29:32 -0500 |
commit | 07e08a881ae177d3e3b7cfd2c5199443c6db3dd0 (patch) | |
tree | 39ba7b6a731f6f24f1ba0d797d52cc7706ed8ac1 /array.c | |
parent | b1062311a3caab9ec89c0f104bd9b4334174f23c (diff) | |
download | egawk-07e08a881ae177d3e3b7cfd2c5199443c6db3dd0.tar.gz egawk-07e08a881ae177d3e3b7cfd2c5199443c6db3dd0.tar.bz2 egawk-07e08a881ae177d3e3b7cfd2c5199443c6db3dd0.zip |
Use unref when freeing a null array element.
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 18 |
1 files changed, 12 insertions, 6 deletions
@@ -798,7 +798,7 @@ asort_actual(int nargs, SORT_CTXT ctxt) { NODE *array, *dest = NULL, *result; NODE *r, *subs, *s; - NODE **list = NULL, **ptr; + NODE **list = NULL, **ptr, **lhs; unsigned long num_elems, i; const char *sort_str; @@ -880,7 +880,9 @@ asort_actual(int nargs, SORT_CTXT ctxt) for (i = 1, ptr = list; i <= num_elems; i++, ptr += 2) { subs = make_number(i); - *assoc_lookup(result, subs) = *ptr; + lhs = assoc_lookup(result, subs); + unref(*lhs); + *lhs = *ptr; unref(subs); } } else { @@ -896,9 +898,11 @@ asort_actual(int nargs, SORT_CTXT ctxt) /* value node */ r = *ptr++; - if (r->type == Node_val) - *assoc_lookup(result, subs) = dupnode(r); - else { + if (r->type == Node_val) { + lhs = assoc_lookup(result, subs); + unref(*lhs); + *lhs = dupnode(r); + } else { NODE *arr; arr = make_array(); subs = force_string(subs); @@ -906,7 +910,9 @@ asort_actual(int nargs, SORT_CTXT ctxt) subs->stptr = NULL; subs->flags &= ~STRCUR; arr->parent_array = array; /* actual parent, not the temporary one. */ - *assoc_lookup(result, subs) = assoc_copy(r, arr); + lhs = assoc_lookup(result, subs); + unref(*lhs); + *lhs = assoc_copy(r, arr); } unref(subs); } |