Skip to content

Commit

Permalink
Fix wrong size malloc and minor memleak(cherry picked from commit e4c…
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 authored and sezero committed Sep 17, 2022
1 parent a861543 commit a137252
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion IMG_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst, int freed
int i;
int last_transparent = -1;

color_ptr = (png_colorp)SDL_malloc(sizeof(png_colorp) * ncolors);
color_ptr = (png_colorp)SDL_malloc(sizeof(png_color) * ncolors);
if (color_ptr == NULL)
{
lib.png_destroy_write_struct(&png_ptr, &info_ptr);
Expand Down Expand Up @@ -656,6 +656,7 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst, int freed

row_pointers = (png_bytep *) SDL_malloc(sizeof(png_bytep) * source->h);
if (!row_pointers) {
free(color_ptr);
lib.png_destroy_write_struct(&png_ptr, &info_ptr);
IMG_SetError("Out of memory");
return -1;
Expand Down

0 comments on commit a137252

Please sign in to comment.