diff -r b1c1ec3a8d49 IMG_xpm.c --- a/IMG_xpm.c Thu Apr 07 07:50:52 2011 -0700 +++ b/IMG_xpm.c Sun Aug 07 01:41:04 2011 -0500 @@ -123,8 +123,10 @@ return NULL; memset(hash->table, 0, bytes); hash->entries = malloc(maxnum * sizeof(struct hash_entry)); - if(!hash->entries) + if(!hash->entries) { + free(hash.table); return NULL; + } hash->next_free = hash->entries; return hash; } @@ -259,11 +261,13 @@ len += 4; /* "\",\n\0" */ if(len > buflen){ buflen = len; - linebuf = realloc(linebuf, buflen); - if(!linebuf) { + linebufnew = realloc(linebuf, buflen); + if(!linebufnew) { + free(linebuf); error = "Out of memory"; return NULL; } + linebuf = linebufnew; } if(SDL_RWread(src, linebuf, len - 1, 1) <= 0) { error = "Premature end of data"; @@ -277,11 +281,13 @@ if(buflen == 0) buflen = 16; buflen *= 2; - linebuf = realloc(linebuf, buflen); - if(!linebuf) { + linebufnew = realloc(linebuf, buflen); + if(!linebufnew) { + free(linebuf); error = "Out of memory"; return NULL; } + linebuf = linebufnew; } if(SDL_RWread(src, linebuf + n, 1, 1) <= 0) { error = "Premature end of data";