4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-19 12:59:21 +08:00

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>
This commit is contained in:
Kuan-Wei Chiu 2023-12-02 00:13:21 +08:00 committed by Corinna Vinschen
parent 10da646880
commit 65f7ab0bb9

View File

@ -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++)