Fix possible memory leak in error conditions when saving resized album art.
This commit is contained in:
parent
a21bbe557d
commit
9eec5b8cac
13
albumart.c
13
albumart.c
@ -80,16 +80,15 @@ save_resized_album_art(image_s *imsrc, const char *path)
|
|||||||
}
|
}
|
||||||
imdst = image_resize(imsrc, dstw, dsth);
|
imdst = image_resize(imsrc, dstw, dsth);
|
||||||
if( !imdst )
|
if( !imdst )
|
||||||
goto error;
|
|
||||||
|
|
||||||
if( image_save_to_jpeg_file(imdst, cache_file) == 0 )
|
|
||||||
{
|
{
|
||||||
image_free(imdst);
|
|
||||||
return cache_file;
|
|
||||||
}
|
|
||||||
error:
|
|
||||||
free(cache_file);
|
free(cache_file);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cache_file = image_save_to_jpeg_file(imdst, cache_file);
|
||||||
|
image_free(imdst);
|
||||||
|
|
||||||
|
return cache_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* And our main album art functions */
|
/* And our main album art functions */
|
||||||
|
@ -838,8 +838,8 @@ image_save_to_jpeg_buf(image_s * pimage, int * size)
|
|||||||
return dst.buf;
|
return dst.buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
char *
|
||||||
image_save_to_jpeg_file(image_s * pimage, const char * path)
|
image_save_to_jpeg_file(image_s * pimage, char * path)
|
||||||
{
|
{
|
||||||
int nwritten, size = 0;
|
int nwritten, size = 0;
|
||||||
unsigned char * buf;
|
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);
|
buf = image_save_to_jpeg_buf(pimage, &size);
|
||||||
if( !buf )
|
if( !buf )
|
||||||
return -1;
|
return NULL;
|
||||||
dst_file = fopen(path, "w");
|
dst_file = fopen(path, "w");
|
||||||
if( !dst_file )
|
if( !dst_file )
|
||||||
{
|
{
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return NULL;
|
||||||
}
|
}
|
||||||
nwritten = fwrite(buf, 1, size, dst_file);
|
nwritten = fwrite(buf, 1, size, dst_file);
|
||||||
fclose(dst_file);
|
fclose(dst_file);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return (nwritten==size ? 0 : 1);
|
return (nwritten == size) ? path : NULL;
|
||||||
}
|
}
|
||||||
|
@ -54,5 +54,5 @@ image_resize(image_s * src_image, int32_t width, int32_t height);
|
|||||||
unsigned char *
|
unsigned char *
|
||||||
image_save_to_jpeg_buf(image_s * pimage, int * size);
|
image_save_to_jpeg_buf(image_s * pimage, int * size);
|
||||||
|
|
||||||
int
|
char *
|
||||||
image_save_to_jpeg_file(image_s * pimage, const char * path);
|
image_save_to_jpeg_file(image_s * pimage, char * path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user