public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] newlib: libc: Fix memory leak in computematchjumps()
@ 2023-12-01 18:29 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-12-01 18:29 UTC (permalink / raw)
To: newlib-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=65f7ab0bb928162f6a6ea60e2803d6b9e5d95e8b
commit 65f7ab0bb928162f6a6ea60e2803d6b9e5d95e8b
Author: Kuan-Wei Chiu <visitorckw@gmail.com>
AuthorDate: Sat Dec 2 00:13:21 2023 +0800
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Fri Dec 1 19:28:55 2023 +0100
newlib: libc: Fix memory leak in computematchjumps()
In cases where malloc fails for the 'g->matchjump' allocation, the code
path does not handle the failure gracefully, potentially leading to a
memory leak. This fix ensures proper cleanup by freeing the allocated
memory for 'pmatches' before returning.
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Diff:
---
newlib/libc/posix/regcomp.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/newlib/libc/posix/regcomp.c b/newlib/libc/posix/regcomp.c
index 002f978cd07c..e71bc005c920 100644
--- a/newlib/libc/posix/regcomp.c
+++ b/newlib/libc/posix/regcomp.c
@@ -2001,8 +2001,10 @@ struct re_guts *g;
}
g->matchjump = (int*) malloc(g->mlen * sizeof(unsigned int));
- if (g->matchjump == NULL) /* Not a fatal error */
- return;
+ if (g->matchjump == NULL) { /* Not a fatal error */
+ free(pmatches);
+ return;
+ }
/* Set maximum possible jump for each character in the pattern */
for (mindex = 0; mindex < g->mlen; mindex++)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-01 18:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-01 18:29 [newlib-cygwin/main] newlib: libc: Fix memory leak in computematchjumps() Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).