From: Torbjörn SVENSSON Date: Thu, 26 Mar 2026 18:02:16 +0000 (+0100) Subject: gcov: return failure if malloc fails X-Git-Tag: basepoints/gcc-17~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=496cfc4897ef0e7f879409e7ab68c011f526ef5d;p=thirdparty%2Fgcc.git gcov: return failure if malloc fails Don't assume that malloc always returns a non-null pointer. xmalloc is sometimes an alias for malloc due to this in libgcc/libgcov.h: /* work around the poisoned malloc/calloc in system.h. */ #ifndef xmalloc #define xmalloc malloc #endif libgcc/ChangeLog: * libgcov-driver-system.c (gcov_exit_open_gcda_file): Handle potential NULL value from malloc. Signed-off-by: Torbjörn SVENSSON --- diff --git a/libgcc/libgcov-driver-system.c b/libgcc/libgcov-driver-system.c index 7b20b29bebf..0991bb57db6 100644 --- a/libgcc/libgcov-driver-system.c +++ b/libgcc/libgcov-driver-system.c @@ -301,6 +301,11 @@ gcov_exit_open_gcda_file (struct gcov_info *gi_ptr, size_t prefix_length = gf->prefix ? strlen (gf->prefix) : 0; gf->filename = (char *) xmalloc (prefix_length + strlen (fname) + 2); + if (!gf->filename) + { + fprintf (stderr, "profiling:Failed to allocate memory for filename"); + return -1; + } *gf->filename = '\0'; if (prefix_length) strcat (gf->filename, gf->prefix);