Bug 27606 - Memory leak in elf/cache.c (write_extensions)
Summary: Memory leak in elf/cache.c (write_extensions)
Status: NEW
Alias: None
Product: glibc
Classification: Unclassified
Component: dynamic-link (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: SAST
Depends on:
Blocks:
 
Reported: 2021-03-18 18:08 UTC by Carlos O'Donell
Modified: 2024-07-08 12:40 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos O'Donell 2021-03-18 18:08:45 UTC
492 static void
 493 write_extensions (int fd, uint32_t str_offset,
 494                   uint32_t cache_extension_offset)
 495 {
 496   assert ((cache_extension_offset % 4) == 0);
 497 
 498   /* The length and contents of the glibc-hwcaps section.  */
 499   uint32_t hwcaps_count = glibc_hwcaps_count ();
 500   uint32_t hwcaps_offset = cache_extension_offset + cache_extension_size;
 501   uint32_t hwcaps_size = hwcaps_count * sizeof (uint32_t);
 502   uint32_t *hwcaps_array = xmalloc (hwcaps_size);

We allocate hwcaps_array.

 545   if (write (fd, ext, ext_size) != ext_size
 546       || write (fd, hwcaps_array, hwcaps_size) != hwcaps_size
 547       || write (fd, generator, strlen (generator)) != strlen (generator))
 548     error (EXIT_FAILURE, errno, _("Writing of cache extension data failed"));
 549 
 550   free (ext);
 551 }
 552 

Then we go out of scope without freeing hwcaps_array.