From 86b94d9feb4195a7a1ac287a2779ea826057b6dd Mon Sep 17 00:00:00 2001 From: atheik <14833674+atheik@users.noreply.github.com> Date: Fri, 11 Mar 2022 20:24:35 +0100 Subject: [PATCH] libast: optget(3): Fix memory leak in --help/--man info src/lib/libast/misc/optget.c: textout(): case ']': - Before returning, call pop() to free any \f...\f info items that are left. Note that this is a safe no-op if the pointer is null. Resolves: https://github.com/ksh93/ksh/issues/407 Co-authored-by: Martijn Dekker --- NEWS | 3 +++ src/cmd/ksh93/tests/leaks.sh | 2 +- src/lib/libast/misc/optget.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ae264a1a8..de32cb3d5 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed another corner case bug in the 'test'/'[' command. +- A memory leak was fixed in the --man self-documentation options + of built-in commands. + 2022-03-05: - The 'enum' command can now create more than one type per invocation. diff --git a/src/cmd/ksh93/tests/leaks.sh b/src/cmd/ksh93/tests/leaks.sh index 287ba62c1..05d8040b1 100755 --- a/src/cmd/ksh93/tests/leaks.sh +++ b/src/cmd/ksh93/tests/leaks.sh @@ -418,7 +418,7 @@ DO DONE # ====== -TEST title='showing --man info' known=y url=https://github.com/ksh93/ksh/issues/407 +TEST title='showing --man info' DO set --man 2>/dev/null ulimit --man 2>/dev/null diff --git a/src/lib/libast/misc/optget.c b/src/lib/libast/misc/optget.c index c0ba75b36..d0c4b07d5 100644 --- a/src/lib/libast/misc/optget.c +++ b/src/lib/libast/misc/optget.c @@ -2157,6 +2157,7 @@ textout(Sfio_t* sp, register char* s, char* conform, int conformlen, int style, break; } } + pop(psp); return s; } s++;