diff options
author | Kuan-Wei Chiu <visitorckw@gmail.com> | 2023-12-02 00:13:21 +0800 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2023-12-01 19:28:55 +0100 |
commit | 65f7ab0bb928162f6a6ea60e2803d6b9e5d95e8b (patch) | |
tree | edce65e9e72891f1aa56d1496bda50ca341478e0 /newlib | |
parent | 10da64688016c0146e049eef3533a35ff19e6b6e (diff) | |
download | newlib-65f7ab0bb928162f6a6ea60e2803d6b9e5d95e8b.zip newlib-65f7ab0bb928162f6a6ea60e2803d6b9e5d95e8b.tar.gz newlib-65f7ab0bb928162f6a6ea60e2803d6b9e5d95e8b.tar.bz2 |
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>
Diffstat (limited to 'newlib')
-rw-r--r-- | newlib/libc/posix/regcomp.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/newlib/libc/posix/regcomp.c b/newlib/libc/posix/regcomp.c index 002f978..e71bc00 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++) |