Allocated string erroneously marked DONTFREE. From Miguel Pineiro Jr.
-/* $OpenBSD: FIXES,v 1.45 2022/06/03 19:42:27 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
This file lists all bug fixes, changes, etc., made since the AWK book
was sent to the printers in August, 1987.
+
+May 23, 2022:
+ Memory leak when assigning a string to some of the built-in
+ variables. allocated string erroneously marked DONTFREE.
+ Thanks to Miguel Pineiro Jr. <mpj@pineiro.cc>.
+
Mar 14, 2022:
- The fulfillment of an assignment operand had been truncating its
- entry in ARGV (since circa 1989). Thanks to Miguel Pineiro Jr.
- <mpj@pineiro.cc>.
+ Historic bug: command-line "name=value" assignment had been
+ truncating its entry in ARGV. (circa 1989) Thanks to
+ Miguel Pineiro Jr. <mpj@pineiro.cc>.
Mar 3, 2022:
Fixed file management memory leak that appears to have been
-/* $OpenBSD: main.c,v 1.53 2022/06/03 19:42:27 millert Exp $ */
+/* $OpenBSD: main.c,v 1.54 2022/06/03 19:46:09 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
THIS SOFTWARE.
****************************************************************/
-const char *version = "version 20220314";
+const char *version = "version 20220530";
#define DEBUG
#include <stdio.h>
-/* $OpenBSD: tran.c,v 1.34 2021/11/02 15:29:41 millert Exp $ */
+/* $OpenBSD: tran.c,v 1.35 2022/06/03 19:46:09 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
extern Cell **fldtab;
-static void
-setfree(Cell *vp)
-{
- if (&vp->sval == FS || &vp->sval == RS ||
- &vp->sval == OFS || &vp->sval == ORS ||
- &vp->sval == OFMT || &vp->sval == CONVFMT ||
- &vp->sval == FILENAME || &vp->sval == SUBSEP)
- vp->tval |= DONTFREE;
- else
- vp->tval &= ~DONTFREE;
-}
-
void syminit(void) /* initialize symbol table with builtin vars */
{
literal0 = setsymtab("0", "0", 0.0, NUM|STR|CON|DONTFREE, symtab);
t = s ? tostring(s) : tostring(""); /* in case it's self-assign */
if (freeable(vp))
xfree(vp->sval);
- vp->tval &= ~(NUM|CONVC|CONVO);
+ vp->tval &= ~(NUM|DONTFREE|CONVC|CONVO);
vp->tval |= STR;
vp->fmt = NULL;
- setfree(vp);
DPRINTF("setsval %p: %s = \"%s (%p) \", t=%o r,f=%d,%d\n",
(void*)vp, NN(vp->nval), t, (void*)t, vp->tval, donerec, donefld);
vp->sval = t;