From: Lutz M. <lu...@us...> - 2004-09-08 06:00:22
|
Update of /cvsroot/libexif/libexif/libexif In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10518/libexif Modified Files: exif-data.c exif-loader.c Log Message: 2004-09-08 Lutz Mueller <lu...@us...> * libexif/exif-loader.c * libexif/exif-data.c: Replace a couple of calls to malloc by calls to calloc. Index: exif-data.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-data.c,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- exif-data.c 7 Sep 2004 06:15:38 -0000 1.46 +++ exif-data.c 8 Sep 2004 06:00:03 -0000 1.47 @@ -58,6 +58,19 @@ unsigned int offset_mnote; }; +static void * +exif_data_alloc (ExifData *data, unsigned int i) +{ + void *d; + + /* This is the only call to calloc in this file. */ + d = calloc (i, 1); + if (d) return d; + + if (data) EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", i); + return NULL; +} + ExifMnoteData * exif_data_get_mnote_data (ExifData *d) { @@ -70,16 +83,10 @@ ExifData *data; unsigned int i; - data = malloc (sizeof (ExifData)); - if (!data) - return (NULL); - memset (data, 0, sizeof (ExifData)); - data->priv = malloc (sizeof (ExifDataPrivate)); - if (!data->priv) { - free (data); - return (NULL); - } - memset (data->priv, 0, sizeof (ExifDataPrivate)); + data = exif_data_alloc (NULL, sizeof (ExifData)); + if (!data) return (NULL); + data->priv = exif_data_alloc (data, sizeof (ExifDataPrivate)); + if (!data->priv) { free (data); return (NULL); } data->priv->ref_count = 1; for (i = 0; i < EXIF_IFD_COUNT; i++) { @@ -135,11 +142,8 @@ if (size < doff + s) return; - entry->data = malloc (s); - if (!entry->data) { - EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", s); - return; - } + entry->data = exif_data_alloc (data, s); + if (!entry->data) return; entry->size = s; memcpy (entry->data, d + doff, s); @@ -217,14 +221,10 @@ (int) ds, (int) offset, (int) size); return; } - if (data->data) - free (data->data); + if (data->data) free (data->data); data->size = size; - data->data = malloc (data->size); - if (!data->data) { - EXIF_LOG_NO_MEMORY (data->priv->log, "ExifData", data->size); - return; - } + data->data = exif_data_alloc (data, data->size); + if (!data->data) return; memcpy (data->data, d + offset, data->size); } @@ -727,9 +727,8 @@ /* Header */ *ds = 14; - *d = malloc (*ds); - if (!*d) - return; + *d = exif_data_alloc (data, *ds); + if (!*d) return; memcpy (*d, ExifHeader, 6); /* Order (offset 6) */ Index: exif-loader.c =================================================================== RCS file: /cvsroot/libexif/libexif/libexif/exif-loader.c,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- exif-loader.c 26 Aug 2004 20:08:09 -0000 1.8 +++ exif-loader.c 8 Sep 2004 06:00:03 -0000 1.9 @@ -31,6 +31,21 @@ ExifLog *log; }; +static void * +exif_loader_alloc (ExifLoader *l, unsigned int i) +{ + void *d; + + if (!i) return NULL; + + /* This is the only call to calloc in this file. */ + d = calloc (i, 1); + if (d) return d; + + if (l) EXIF_LOG_NO_MEMORY (l->log, "ExifLog", i); + return NULL; +} + #undef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -143,7 +158,7 @@ if (eld->state == EL_EXIF_FOUND && len_remain > 0) { if (eld->buf == NULL) { - eld->buf = malloc (sizeof (unsigned char) * eld->size); + eld->buf = exif_loader_alloc (eld, eld->size); if (!eld->buf) return 0; eld->bytes_read = 0; } @@ -168,10 +183,10 @@ ExifLoader * exif_loader_new (void) { - ExifLoader *loader = malloc (sizeof (ExifLoader)); - + ExifLoader *loader; + + loader = exif_loader_alloc (NULL, sizeof (ExifLoader)); if (!loader) return NULL; - memset (loader, 0, sizeof (ExifLoader)); loader->ref_count = 1; return loader; |