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 <torbjorn.svensson@foss.st.com>
This commit is contained in:
Torbjörn SVENSSON
2026-03-26 19:02:16 +01:00
parent 8e510c72ed
commit 496cfc4897

View File

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