aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authorjohn haque <j.eh@mchsi.com>2012-04-17 13:29:32 -0500
committerjohn haque <j.eh@mchsi.com>2012-04-17 13:29:32 -0500
commit07e08a881ae177d3e3b7cfd2c5199443c6db3dd0 (patch)
tree39ba7b6a731f6f24f1ba0d797d52cc7706ed8ac1 /array.c
parentb1062311a3caab9ec89c0f104bd9b4334174f23c (diff)
downloadegawk-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.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/array.c b/array.c
index c8e230f7..a0c74e9b 100644
--- a/array.c
+++ b/array.c
@@ -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);
}