We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1831 - Memory leak issue in SDL_image-1.2.12/IMG_xpm.c file
Summary: Memory leak issue in SDL_image-1.2.12/IMG_xpm.c file
Status: RESOLVED FIXED
Alias: None
Product: SDL_image
Classification: Unclassified
Component: misc (show other bugs)
Version: 1.2.12
Hardware: x86 Linux
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-02 04:36 UTC by Nitz
Modified: 2013-05-22 00:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nitz 2013-05-02 04:36:23 UTC
static struct color_hash *create_colorhash(int maxnum)
{
     int bytes, s;
     struct color_hash *hash;

     /* we know how many entries we need, so we can allocate
        everything here */
     hash = malloc(sizeof *hash);
     if(!hash)
      return NULL;

     /* use power-of-2 sized hash table for decoding speed */
     for(s = STARTING_HASH_SIZE; s < maxnum; s <<= 1)
          ;
     hash->size = s;
     hash->maxnum = maxnum;
     bytes = hash->size * sizeof(struct hash_entry **);
     hash->entries = NULL; /* in case malloc fails */
     hash->table = malloc(bytes);
     if(!hash->table)

     {

       free(hash);  // 1) This line is added
       return NULL;

     }
     memset(hash->table, 0, bytes);
     hash->entries = malloc(maxnum * sizeof(struct hash_entry));
     if(!hash->entries) {
      free(hash->table);

      free(hash);  // 2) This line is added
      return NULL;
     }
     hash->next_free = hash->entries;
     return hash;
}  

In this code hash memory is dynamically allocated, but its getting leak at 2 points.

So its important to free this hash memory, Patch is applied at 2 points.

Thanks & Regards,
Nitz
Comment 1 Sam Lantinga 2013-05-22 00:36:10 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL_image/rev/35beff028453