| Summary: | Memory leak issue in SDL_image-1.2.12/IMG_xpm.c file | ||
|---|---|---|---|
| Product: | SDL_image | Reporter: | Nitz <nitin.j4> |
| Component: | misc | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | ||
| Version: | 1.2.12 | ||
| Hardware: | x86 | ||
| OS: | Linux | ||
Fixed, thanks! http://hg.libsdl.org/SDL_image/rev/35beff028453 |
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