X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fshare%2Fgrabbag%2Fpicture.c;h=965a7b34984cea42d4eaa2cae4ef49139d5e61ea;hb=f25b2602dce3c09098e3092bfad983e3ec7fdb4f;hp=5dec8fc922b2a38a347e2e3413649f490d766aa0;hpb=82b128050e9e58a34baf8aa188077ddeee2d7a1a;p=platform%2Fupstream%2Fflac.git diff --git a/src/share/grabbag/picture.c b/src/share/grabbag/picture.c index 5dec8fc..965a7b3 100644 --- a/src/share/grabbag/picture.c +++ b/src/share/grabbag/picture.c @@ -1,5 +1,5 @@ /* grabbag - Convenience lib for various routines common to several tools - * Copyright (C) 2006,2007,2008 Josh Coalson + * Copyright (C) 2006,2007,2008,2009 Josh Coalson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -11,9 +11,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #if HAVE_CONFIG_H @@ -26,11 +26,12 @@ #include #include #include +#include "share/compat.h" /* slightly different that strndup(): this always copies 'size' bytes starting from s into a NUL-terminated string. */ static char *local__strndup_(const char *s, size_t size) { - char *x = (char*)safe_malloc_add_2op_(size, /*+*/1); + char *x = safe_malloc_add_2op_(size, /*+*/1); if(x) { memcpy(x, s, size); x[size] = '\0'; @@ -287,8 +288,10 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con *error_message = 0; - if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE))) + if(0 == (obj = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PICTURE))) { *error_message = error_messages[0]; + return obj; + } if(strchr(spec, '|')) { /* full format */ const char *p; @@ -354,17 +357,19 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con *error_message = error_messages[3]; } else { /* regular picture file */ - const off_t size = grabbag__file_get_filesize(spec); + const FLAC__off_t size = grabbag__file_get_filesize(spec); if(size < 0) *error_message = error_messages[5]; else { - FLAC__byte *buffer = (FLAC__byte*)safe_malloc_(size); + FLAC__byte *buffer = safe_malloc_(size); if(0 == buffer) *error_message = error_messages[0]; else { FILE *f = fopen(spec, "rb"); - if(0 == f) + if(0 == f) { *error_message = error_messages[5]; + free(buffer); + } else { if(fread(buffer, 1, size, f) != (size_t)size) *error_message = error_messages[6]; @@ -379,6 +384,9 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con else if((obj->data.picture.width == 0 || obj->data.picture.height == 0 || obj->data.picture.depth == 0) && !local__extract_resolution_color_info_(&obj->data.picture)) *error_message = error_messages[4]; } + else { + free(buffer); + } } } } @@ -388,7 +396,7 @@ FLAC__StreamMetadata *grabbag__picture_parse_specification(const char *spec, con if(*error_message == 0) { if( - obj->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD && + obj->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD && ( (strcmp(obj->data.picture.mime_type, "image/png") && strcmp(obj->data.picture.mime_type, "-->")) || obj->data.picture.width != 32 ||