1
0
mirror of https://github.com/openbsd/src.git synced 2026-05-01 17:46:35 +00:00

fix two leaks in interpreter.c; from Han Boetes (hboetes at gmail)

- upon redefinition of a variable, free the content of the old varentry
- free v1 if strndup fails, and delay the SLIST_INSERT_HEAD
This commit is contained in:
op
2026-02-22 10:31:28 +00:00
parent c745d9d774
commit 266e2f0407

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: interpreter.c,v 1.36 2024/09/20 02:00:46 jsg Exp $ */
/* $OpenBSD: interpreter.c,v 1.37 2026/02/22 10:31:28 op Exp $ */
/*
* This file is in the public domain.
*
@@ -592,15 +592,20 @@ founddef(char *defstr, int blkid, int expctr, int hasval, int elen)
if (!SLIST_EMPTY(&varhead)) {
SLIST_FOREACH_SAFE(v1, &varhead, entry, vt) {
if (strcmp(vnamep, v1->v_name) == 0)
if (strcmp(vnamep, v1->v_name) == 0) {
SLIST_REMOVE(&varhead, v1, varentry, entry);
free(v1->v_name);
free(v1);
}
}
}
if ((v1 = malloc(sizeof(struct varentry))) == NULL)
return (ABORT);
SLIST_INSERT_HEAD(&varhead, v1, entry);
if ((v1->v_name = strndup(vnamep, BUFSIZE)) == NULL)
if ((v1->v_name = strndup(vnamep, BUFSIZE)) == NULL) {
free(v1);
return(dobeep_msg("strndup error"));
}
SLIST_INSERT_HEAD(&varhead, v1, entry);
vnamep = v1->v_name;
v1->v_count = 0;
v1->v_vals = NULL;