aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xChangeLog5
-rw-r--r--awk.h15
2 files changed, 20 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index da93370e..f90a00fd 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2019-01-14 Andrew J. Schorr <aschorr@telemetry-investments.com>
+ * awk.h (assoc_set): Add new inline function to set an array element
+ to eliminate code duplication and reduce the chance of memory leaks.
+
+2019-01-14 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
* builtin.c (do_typeof): Fix memory leak when populating the
optional array, and make sure to call the astore method.
diff --git a/awk.h b/awk.h
index bac788b3..9b5d359c 100644
--- a/awk.h
+++ b/awk.h
@@ -1362,6 +1362,21 @@ extern int fatal_tag_valid;
/* assoc_remove --- remove an index from symbol[] */
#define assoc_remove(a, s) ((a)->aremove(a, s) != NULL)
+/* assoc_set -- set an element in an array */
+
+static inline void
+assoc_set(NODE *array, NODE *sub, NODE *value)
+{
+
+ NODE **lhs = assoc_lookup(array, sub);
+ unref(*lhs);
+ *lhs = value;
+ if (array->astore != NULL)
+ (*array->astore)(array, sub);
+ unref(sub);
+}
+
+
/* ------------- Function prototypes or defs (as appropriate) ------------- */
/* array.c */
typedef enum { SORTED_IN = 1, ASORT, ASORTI } sort_context_t;