Fix possible memory leak in error conditions when saving resized album art.

This commit is contained in:
Justin Maggard 2014-01-16 16:07:53 -08:00
parent a21bbe557d
commit 9eec5b8cac
3 changed files with 15 additions and 16 deletions

View File

@ -80,18 +80,17 @@ save_resized_album_art(image_s *imsrc, const char *path)
}
imdst = image_resize(imsrc, dstw, dsth);
if( !imdst )
goto error;
if( image_save_to_jpeg_file(imdst, cache_file) == 0 )
{
image_free(imdst);
return cache_file;
}
error:
free(cache_file);
return NULL;
}
cache_file = image_save_to_jpeg_file(imdst, cache_file);
image_free(imdst);
return cache_file;
}
/* And our main album art functions */
void
update_if_album_art(const char *path)

View File

@ -838,8 +838,8 @@ image_save_to_jpeg_buf(image_s * pimage, int * size)
return dst.buf;
}
int
image_save_to_jpeg_file(image_s * pimage, const char * path)
char *
image_save_to_jpeg_file(image_s * pimage, char * path)
{
int nwritten, size = 0;
unsigned char * buf;
@ -847,16 +847,16 @@ image_save_to_jpeg_file(image_s * pimage, const char * path)
buf = image_save_to_jpeg_buf(pimage, &size);
if( !buf )
return -1;
return NULL;
dst_file = fopen(path, "w");
if( !dst_file )
{
free(buf);
return -1;
return NULL;
}
nwritten = fwrite(buf, 1, size, dst_file);
fclose(dst_file);
free(buf);
return (nwritten==size ? 0 : 1);
return (nwritten == size) ? path : NULL;
}

View File

@ -54,5 +54,5 @@ image_resize(image_s * src_image, int32_t width, int32_t height);
unsigned char *
image_save_to_jpeg_buf(image_s * pimage, int * size);
int
image_save_to_jpeg_file(image_s * pimage, const char * path);
char *
image_save_to_jpeg_file(image_s * pimage, char * path);