From: hj kim Date: Thu, 16 Apr 2020 09:32:00 +0000 (+0900) Subject: Remove out of memory related code by using glib APIs X-Git-Tag: submit/tizen/20200428.070655^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f8833308ac9a136676a9ee0d469887edb9e6d46c;p=platform%2Fcore%2Fmultimedia%2Flibmm-utility.git Remove out of memory related code by using glib APIs glib's memory managed as below. If any call to allocate memory fails, the application is terminated. This also means that there is no need to check if the call succeeded. Change-Id: Ib9fc815db542efcf9c5e62e8cb6cc7df684b574b --- diff --git a/bmp/test/mm_util_bmp_testsuite.c b/bmp/test/mm_util_bmp_testsuite.c index 03754f0..1676fd4 100644 --- a/bmp/test/mm_util_bmp_testsuite.c +++ b/bmp/test/mm_util_bmp_testsuite.c @@ -99,13 +99,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) } rewind(fp); - *data = (void *)calloc(1, len); - if (*data == NULL) { - fprintf(stderr, "\tmemory allocation failed \n"); - fclose(fp); - return FALSE; - } - + *data = g_malloc0(len); *length = fread(*data, 1, (size_t)len, fp); if (*length != len) { fprintf(stderr, "\t[BMP_testsuite] fread failed \n"); @@ -113,11 +107,6 @@ static gboolean _read_file(char *path, void **data, size_t *length) fclose(fp); - if (*data == NULL) { - *length = 0; - return FALSE; - } - *length = (size_t)len; fprintf(stderr, "\t[BMP_testsuite] %s %zu read DONE\n", path, *length); @@ -342,7 +331,7 @@ gboolean _test_auto() fprintf(stderr, "\t[BMP_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]); - SAFE_FREE(g_readed_data); + g_free(g_readed_data); SAFE_IMAGE_FREE(g_decoded_data); test_mode++; } @@ -387,7 +376,7 @@ int main(int argc, char *argv[]) out: g_free(g_path); - SAFE_FREE(g_readed_data); + g_free(g_readed_data); SAFE_IMAGE_FREE(g_decoded_data); return 0; diff --git a/common/mm_util_image.c b/common/mm_util_image.c index c3b88f5..8a89181 100755 --- a/common/mm_util_image.c +++ b/common/mm_util_image.c @@ -59,23 +59,15 @@ int mm_image_create_image(unsigned int width, unsigned int height, mm_util_sec_debug("w [%u], h [%u], color [%u], data [%p], size [%zu]", width, height, color, data, size); - _image = (mm_image_info_s *)calloc(1, sizeof(mm_image_info_s)); - mm_util_retvm_if((_image == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); + _image = g_new0(mm_image_info_s, 1); /* Just TEMP_DATA_SIZE has been used internally. * It will be removed after removing deprecated CAPIs. */ - if (size == TEMP_DATA_SIZE) { + if (size == TEMP_DATA_SIZE) _image->data = (unsigned char *)data; - } else { - _image->data = calloc(1, size); - if (_image->data == NULL) { - mm_util_error("Memory allocation failed"); - mm_image_destroy_image(_image); - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } - - memcpy(_image->data, data, size); - } + else + _image->data = g_memdup(data, size); + _image->size = size; _image->width = width; _image->height = height; @@ -96,8 +88,7 @@ int mm_image_clone_image(mm_util_image_h src, mm_util_image_h *dst) mm_util_retvm_if(!src, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid src"); mm_util_retvm_if(!dst, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid dst"); - _dst = (mm_image_info_s *)calloc(1, sizeof(mm_image_info_s)); - mm_util_retvm_if((_dst == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); + _dst = g_new0(mm_image_info_s, 1); _dst->width = _src->width; _dst->height = _src->height; @@ -142,7 +133,6 @@ int mm_image_get_image(mm_util_image_h image, unsigned int *width, unsigned char **data, size_t *size) { mm_image_info_s *_image = (mm_image_info_s *)image; - unsigned char *_data = NULL; mm_util_retvm_if(!IS_VALID_IMAGE(image), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid image"); /* Just TEMP_DATA_SIZE has been used internally. @@ -159,10 +149,7 @@ int mm_image_get_image(mm_util_image_h image, unsigned int *width, *color = _image->color; if (data && size) { - _data = calloc(1, _image->size); - mm_util_retvm_if(_data == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); - memcpy(_data, _image->data, _image->size); - *data = _data; + *data = g_memdup(_image->data, _image->size); *size = _image->size; } @@ -178,6 +165,6 @@ void mm_image_destroy_image(mm_util_image_h image) /* Just TEMP_DATA_SIZE has been used internally. * It will be removed after removing deprecated CAPIs. */ if (_image->size != TEMP_DATA_SIZE) - MMUTIL_SAFE_FREE(_image->data); - MMUTIL_SAFE_FREE(_image); + g_free(_image->data); + g_free(_image); } diff --git a/gif/mm_util_gif.c b/gif/mm_util_gif.c index 63dd688..8a66f43 100644 --- a/gif/mm_util_gif.c +++ b/gif/mm_util_gif.c @@ -88,9 +88,10 @@ static void __gif_free_frame_buffer(GifRowType *frame_buffer, unsigned int size) if (!frame_buffer) return; - for (idx = 0; idx < (int)size; idx++) - MMUTIL_SAFE_FREE(frame_buffer[idx]); - free(frame_buffer); + for (idx = 0; idx < size; idx++) + g_free(frame_buffer[idx]); + + g_free(frame_buffer); } static int __gif_generate_frame_buffer(GifFileType *gif_image, GifRowType **screen_buf) @@ -99,28 +100,17 @@ static int __gif_generate_frame_buffer(GifFileType *gif_image, GifRowType **scre size_t row_size = 0; GifRowType* _screen_buf = NULL; - _screen_buf = (GifRowType *)calloc(1, gif_image->SHeight * sizeof(GifRowType)); - mm_util_retvm_if(!_screen_buf, MM_UTIL_ERROR_OUT_OF_MEMORY, "Failed to allocate memory required, aborted."); + _screen_buf = g_new0(GifRowType, gif_image->SHeight); row_size = gif_image->SWidth * sizeof(GifPixelType); /* Size in bytes one row. */ - if ((_screen_buf[0] = (GifRowType) calloc(1, row_size)) == NULL) { /* First row. */ - mm_util_error("Failed to allocate memory required, aborted."); - MMUTIL_SAFE_FREE(_screen_buf); - return MM_UTIL_ERROR_INVALID_OPERATION; - } + _screen_buf[0] = g_malloc0(row_size); for (idx = 0; idx < (int)(gif_image->SWidth); idx++) /* Set its color to BackGround. */ _screen_buf[0][idx] = gif_image->SBackGroundColor; for (idx = 1; idx < (int)(gif_image->SHeight); idx++) { /* Allocate the other rows, and set their color to background too: */ - if ((_screen_buf[idx] = (GifRowType) calloc(1, row_size)) == NULL) { - mm_util_error("Failed to allocate memory required, aborted."); - __gif_free_frame_buffer(_screen_buf, idx - 1); - return MM_UTIL_ERROR_INVALID_OPERATION; - } - - memcpy(_screen_buf[idx], _screen_buf[0], row_size); + _screen_buf[idx] = g_memdup(_screen_buf[0], row_size); } *screen_buf = _screen_buf; @@ -206,10 +196,7 @@ static int __gif_convert_to_rgba(void **data, ColorMapObject *color_map, GifRowT mm_util_fenter(); - if ((*data = (void *)calloc(1, width * height * 4)) == NULL) { - mm_util_error("Failed to allocate memory required, aborted."); - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } + *data = g_malloc0(width * height * 4); buffer = (GifByteType *) *data; for (i = 0; i < height; i++) { @@ -313,7 +300,7 @@ static int __read_gif(const char *file_path, void *memory, const size_t src_size } ret = mm_image_create_image(GifFile->SWidth, GifFile->SHeight, MM_UTIL_COLOR_RGBA, image_buffer, GifFile->SWidth * GifFile->SHeight * 4, decoded); - MMUTIL_SAFE_FREE(image_buffer); + g_free(image_buffer); error: __gif_free_frame_buffer(frame_buffer, GifFile->SHeight); @@ -486,18 +473,11 @@ static int __write_gif_to_file(gif_file_s *handle) static int __write_gif_to_buffer(gif_file_s *handle) { - unsigned char *_buffer = NULL; - mm_util_retvm_if(!handle, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle"); mm_util_retvm_if(!handle->io_buf.buf || handle->io_buf.buf_size == 0, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid io_buf"); mm_util_retvm_if(!handle->enc_buffer || !handle->enc_buffer_size, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid buffer"); - _buffer = (unsigned char *)calloc(1, handle->io_buf.buf_size); - mm_util_retvm_if(!_buffer, MM_UTIL_ERROR_OUT_OF_MEMORY, "memory allocation failed"); - - memcpy(_buffer, handle->io_buf.buf, handle->io_buf.buf_size); - - *handle->enc_buffer = _buffer; + *handle->enc_buffer = g_memdup(handle->io_buf.buf, handle->io_buf.buf_size);; *handle->enc_buffer_size = handle->io_buf.buf_size; return MM_UTIL_ERROR_NONE; @@ -552,23 +532,14 @@ static int __gif_image_create_ext_block(int function, int byte_count, ExtensionB mm_util_retvm_if(ext_block == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); /* get allocated extention block */ - _ext_block = (ExtensionBlock *)calloc(1, sizeof(ExtensionBlock)); - if (_ext_block == NULL) { - mm_util_error("Memory allocation failed"); - *ext_block = NULL; - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } + _ext_block = g_new0(ExtensionBlock, 1); _ext_block->Function = function; _ext_block->ByteCount = byte_count; - _ext_block->Bytes = (GifByteType *)calloc(1, (sizeof(GifByteType) * byte_count)); - if (_ext_block->Bytes == NULL) { - mm_util_error("Memory allocation failed"); - MMUTIL_SAFE_FREE(_ext_block); - return MM_UTIL_ERROR_OUT_OF_MEMORY; - } + _ext_block->Bytes = g_new0(GifByteType, byte_count); *ext_block = _ext_block; + return MM_UTIL_ERROR_NONE; } @@ -597,8 +568,8 @@ static int __gif_image_write_ext_block(gif_file_s *gif_file, unsigned int delay_ } /* release extension blocks */ - MMUTIL_SAFE_FREE(_ext_block->Bytes); - MMUTIL_SAFE_FREE(_ext_block); + g_free(_ext_block->Bytes); + g_free(_ext_block); return MM_UTIL_ERROR_NONE; } @@ -607,12 +578,10 @@ int mm_util_gif_encode_create(mm_gif_file_h *gif_file_h) { gif_file_s *gif_file = NULL; - mm_util_retvm_if(gif_file_h == NULL, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter"); + mm_util_retvm_if(!gif_file_h, MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid handle"); - gif_file = (gif_file_s *)calloc(1, sizeof(gif_file_s)); - mm_util_retvm_if(gif_file == NULL, MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); + gif_file = g_new0(gif_file_s, 1); - /* initialize data before set */ *gif_file_h = (mm_gif_file_h)gif_file; return MM_UTIL_ERROR_NONE; @@ -833,5 +802,5 @@ void mm_util_gif_encode_destroy(mm_gif_file_h gif_file_h) g_free(gif_file->filename); MMUTIL_SAFE_FREE(gif_file->io_buf.buf); - MMUTIL_SAFE_FREE(gif_file); + g_free(gif_file); } diff --git a/gif/test/mm_util_gif_testsuite.c b/gif/test/mm_util_gif_testsuite.c index e8eefd2..238f28b 100644 --- a/gif/test/mm_util_gif_testsuite.c +++ b/gif/test/mm_util_gif_testsuite.c @@ -100,13 +100,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) } rewind(fp); - *data = (void *)calloc(1, len); - if (*data == NULL) { - fprintf(stderr, "\tmemory allocation failed \n"); - fclose(fp); - return FALSE; - } - + *data = g_malloc0(len); *length = fread(*data, 1, (size_t)len, fp); if (*length != len) { fprintf(stderr, "\t[GIF_testsuite] fread failed \n"); @@ -114,11 +108,6 @@ static gboolean _read_file(char *path, void **data, size_t *length) fclose(fp); - if (*data == NULL) { - *length = 0; - return FALSE; - } - *length = (size_t)len; fprintf(stderr, "\t[GIF_testsuite] %s %zu read DONE\n", path, *length); @@ -342,7 +331,7 @@ gboolean _test_auto() fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]); - SAFE_FREE(g_readed_data); + g_free(g_readed_data); SAFE_IMAGE_FREE(g_decoded_data); test_mode++; } diff --git a/imgcv/mm_util_imgcv.cpp b/imgcv/mm_util_imgcv.cpp index b9b589e..5f36ef3 100755 --- a/imgcv/mm_util_imgcv.cpp +++ b/imgcv/mm_util_imgcv.cpp @@ -143,13 +143,16 @@ static int __mm_util_imgcv_calculate_hist(mm_util_imgcv_s *handle, unsigned char int mm_util_cv_extract_representative_color(void *image_buffer, int width, int height, unsigned char *r_color, unsigned char *g_color, unsigned char *b_color) { - mm_util_fenter(); + int ret = MM_UTIL_ERROR_NONE; + mm_util_imgcv_s *handle = NULL; mm_util_retvm_if(!image_buffer, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image_buffer"); - mm_util_imgcv_s *handle = (mm_util_imgcv_s *)calloc(1, sizeof(mm_util_imgcv_s)); - mm_util_retvm_if(!handle, MM_UTIL_ERROR_OUT_OF_MEMORY, "fail to create handle"); - int ret = __mm_util_imgcv_init(handle, width, height, image_buffer); + mm_util_fenter(); + + handle = g_new0(mm_util_imgcv_s, 1); + + ret = __mm_util_imgcv_init(handle, width, height, image_buffer); if (ret != MM_UTIL_ERROR_NONE) { mm_util_error("#ERROR#: Fail to __mm_util_imgcv_init: ret=%d", ret); goto ERROR; @@ -164,7 +167,7 @@ int mm_util_cv_extract_representative_color(void *image_buffer, int width, int h ERROR: __mm_util_imgcv_uninit(handle); - MMUTIL_SAFE_FREE(handle); + g_free(handle); mm_util_fleave(); diff --git a/imgp/mm_util_imgp.c b/imgp/mm_util_imgp.c index b0d5c8d..3049f2f 100644 --- a/imgp/mm_util_imgp.c +++ b/imgp/mm_util_imgp.c @@ -316,7 +316,7 @@ static void __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s) if (module) g_module_close(module); - MMUTIL_SAFE_FREE(_imgp_info_s); + g_free(_imgp_info_s); } static void __mm_util_crop_rgb32(const unsigned char *src, unsigned int src_width, unsigned int src_height, @@ -468,6 +468,7 @@ int mm_util_convert_colorspace(mm_util_image_h src, mm_util_color_format_e color unsigned char *output_buffer = NULL; mm_image_info_s *_src = (mm_image_info_s *)src; mm_util_image_h _convert_image = NULL; + imgp_info_s *_imgp_info_s = NULL; mm_util_fenter(); @@ -484,12 +485,7 @@ int mm_util_convert_colorspace(mm_util_image_h src, mm_util_color_format_e color return MM_UTIL_ERROR_INVALID_OPERATION; } - imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); - if (_imgp_info_s == NULL) { - mm_util_error("ERROR - alloc handle"); - ret = MM_UTIL_ERROR_OUT_OF_MEMORY; - goto ERROR; - } + _imgp_info_s = g_new0(imgp_info_s, 1); ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, color, _src->width, _src->height, MM_UTIL_ROTATE_0); if (ret != MM_UTIL_ERROR_NONE) { @@ -546,6 +542,7 @@ int mm_util_resize_image(mm_util_image_h src, unsigned int width, unsigned int h unsigned char *output_buffer = NULL; mm_image_info_s *_src = (mm_image_info_s *)src; mm_util_image_h _resize_image = NULL; + imgp_info_s *_imgp_info_s = NULL; mm_util_fenter(); @@ -560,12 +557,7 @@ int mm_util_resize_image(mm_util_image_h src, unsigned int width, unsigned int h _mm_util_imgp_func = __mm_util_initialize(IMGP_RSZ, _src->color, 0, &_module); mm_util_retvm_if(_mm_util_imgp_func == NULL, MM_UTIL_ERROR_INVALID_OPERATION, "fail __mm_util_initialize"); - imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); - if (_imgp_info_s == NULL) { - mm_util_error("ERROR - alloc handle"); - ret = MM_UTIL_ERROR_OUT_OF_MEMORY; - goto ERROR; - } + _imgp_info_s = g_new0(imgp_info_s, 1); ret = __mm_set_imgp_info_s(_imgp_info_s, _src->color, _src->width, _src->height, _src->color, width, height, MM_UTIL_ROTATE_0); if (ret != MM_UTIL_ERROR_NONE) { @@ -633,6 +625,7 @@ int mm_util_rotate_image(mm_util_image_h src, mm_util_img_rotate_type angle, mm_ unsigned int uint_h = 0; mm_image_info_s *_src = (mm_image_info_s *)src; mm_util_image_h _rotate_image = NULL; + imgp_info_s *_imgp_info_s = NULL; mm_util_fenter(); @@ -649,12 +642,7 @@ int mm_util_rotate_image(mm_util_image_h src, mm_util_img_rotate_type angle, mm_ return MM_UTIL_ERROR_INVALID_OPERATION; } - imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s)); - if (_imgp_info_s == NULL) { - mm_util_error("ERROR - alloc handle"); - ret = MM_UTIL_ERROR_OUT_OF_MEMORY; - goto ERROR; - } + _imgp_info_s = g_new0(imgp_info_s, 1); if ((angle == MM_UTIL_ROTATE_90) || (angle == MM_UTIL_ROTATE_270)) { uint_w = _src->height; @@ -768,8 +756,7 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s __mm_util_get_crop_image_size(_src->color, _width, _height, &_buffer_size); mm_util_retvm_if(!_buffer_size, MM_UTIL_ERROR_INVALID_OPERATION, "fail to get dst_buf_size"); - _buffer = calloc(1, _buffer_size); - mm_util_retvm_if(!_buffer, MM_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed"); + _buffer = g_malloc0(_buffer_size); switch (_src->color) { case MM_UTIL_COLOR_RGB16: { @@ -794,13 +781,13 @@ int mm_util_crop_image(mm_util_image_h src, unsigned int start_x, unsigned int s } default: mm_util_debug("Not supported format"); - MMUTIL_SAFE_FREE(_buffer); + g_free(_buffer); return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT; } ret = mm_image_create_image(_width, _height, _src->color, _buffer, _buffer_size, dst); - MMUTIL_SAFE_FREE(_buffer); + g_free(_buffer); mm_util_fleave(); return ret; diff --git a/imgp/test/mm_util_imgp_testsuite.c b/imgp/test/mm_util_imgp_testsuite.c index 7f1b654..7589011 100644 --- a/imgp/test/mm_util_imgp_testsuite.c +++ b/imgp/test/mm_util_imgp_testsuite.c @@ -96,13 +96,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) } rewind(fp); - *data = (void *)calloc(1, len); - if (*data == NULL) { - fprintf(stderr, "\tmemory allocation failed \n"); - fclose(fp); - return FALSE; - } - + *data = g_malloc0(len); *length = fread(*data, 1, (size_t)len, fp); if (*length != len) { fprintf(stderr, "\t[IMGP_testsuite] fread failed \n"); @@ -110,11 +104,6 @@ static gboolean _read_file(char *path, void **data, size_t *length) fclose(fp); - if (*data == NULL) { - *length = 0; - return FALSE; - } - *length = (size_t)len; fprintf(stderr, "\t[IMGP_testsuite] %s %zu read DONE\n", path, *length); diff --git a/jpeg/mm_util_jpeg.c b/jpeg/mm_util_jpeg.c index 9f21c12..284e17a 100644 --- a/jpeg/mm_util_jpeg.c +++ b/jpeg/mm_util_jpeg.c @@ -211,15 +211,8 @@ static int __jpeg_encode_yuv(j_compress_ptr cinfo, unsigned int width, unsigned void *small_rect= NULL; if (cinfo->image_height - MM_UTIL_ROUND_DOWN_16(height)) { - large_rect = calloc(1, width); - small_rect = calloc(1, width); - - if (!large_rect || !small_rect) { - MMUTIL_SAFE_FREE(large_rect); - MMUTIL_SAFE_FREE(small_rect); - mm_util_error("Temprary rectangles are not allocated"); - return MM_UTIL_ERROR_INVALID_PARAMETER; - } + large_rect = g_malloc0(width); + small_rect = g_malloc0(width); memset(large_rect, 0x10, width); memset(small_rect, 0x80, width); @@ -249,8 +242,8 @@ static int __jpeg_encode_yuv(j_compress_ptr cinfo, unsigned int width, unsigned } } jpeg_write_raw_data(cinfo, data, 16); - MMUTIL_SAFE_FREE(large_rect); - MMUTIL_SAFE_FREE(small_rect); + g_free(large_rect); + g_free(small_rect); return MM_UTIL_ERROR_NONE; } else { @@ -429,12 +422,8 @@ static int __mm_util_jpeg_decode(mm_util_jpeg_ctrl_format_e control_format, FILE goto END; } - image_buffer = (void *) calloc(1, image_buffer_size); - if (!image_buffer) { - mm_util_error("image_buf is NULL"); - ret = MM_UTIL_ERROR_OUT_OF_MEMORY; - goto END; - } + image_buffer = g_malloc0(image_buffer_size); + mm_util_debug("decoded_data->data"); /* while (scan lines remain to be read) jpeg_read_scanlines(...); */ @@ -473,7 +462,7 @@ static int __mm_util_jpeg_decode(mm_util_jpeg_ctrl_format_e control_format, FILE } ret = mm_image_create_image(dinfo.output_width, dinfo.output_height, color_format, image_buffer, image_buffer_size, decoded); - MMUTIL_SAFE_FREE(image_buffer); + g_free(image_buffer); END: /* Finish decompression */ diff --git a/jpeg/test/mm_util_jpeg_testsuite.c b/jpeg/test/mm_util_jpeg_testsuite.c index f0b92b0..f97880d 100644 --- a/jpeg/test/mm_util_jpeg_testsuite.c +++ b/jpeg/test/mm_util_jpeg_testsuite.c @@ -102,13 +102,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) } rewind(fp); - *data = (void *)calloc(1, len); - if (*data == NULL) { - fprintf(stderr, "\tmemory allocation failed \n"); - fclose(fp); - return FALSE; - } - + *data = g_malloc0(len); *length = fread(*data, 1, (size_t)len, fp); if (*length != len) { fprintf(stderr, "\t[JPEG_testsuite] fread failed \n"); @@ -116,11 +110,6 @@ static gboolean _read_file(char *path, void **data, size_t *length) fclose(fp); - if (*data == NULL) { - *length = 0; - return FALSE; - } - *length = (size_t)len; fprintf(stderr, "\t[JPEG_testsuite] %s %zu read DONE\n", path, *length); diff --git a/magick/mm_util_magick.c b/magick/mm_util_magick.c index df55d40..f163c95 100644 --- a/magick/mm_util_magick.c +++ b/magick/mm_util_magick.c @@ -456,17 +456,12 @@ static int __mm_util_read_tmp_file(const char *path, void **data, size_t *length } rewind(fp); - _data = (void *)calloc(1, _length); - if (!_data) { - mm_util_stderror("calloc failed"); - ret = MM_UTIL_ERROR_OUT_OF_MEMORY; - goto ERROR; - } + _data = g_malloc0(_length); if (fread(_data, 1, _length, fp) != _length) { mm_util_stderror("fread failed"); ret = MM_UTIL_ERROR_INVALID_OPERATION; - MMUTIL_SAFE_FREE(_data); + g_free(_data); goto ERROR; } @@ -1167,7 +1162,7 @@ ERROR: if (g_remove(tmp_file) != 0) mm_util_sec_debug("Temporary file was not removed [%s]", tmp_file); - MMUTIL_SAFE_FREE(tmp_file); + g_free(tmp_file); mm_util_fleave(); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index 7e9d005..63bc55c 100644 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.1.40 +Version: 0.1.41 Release: 0 Group: System/Libraries License: Apache-2.0 diff --git a/png/test/mm_util_png_testsuite.c b/png/test/mm_util_png_testsuite.c index a2b1823..c484a15 100644 --- a/png/test/mm_util_png_testsuite.c +++ b/png/test/mm_util_png_testsuite.c @@ -100,13 +100,7 @@ static gboolean _read_file(char *path, void **data, size_t *length) } rewind(fp); - *data = (void *)calloc(1, len); - if (*data == NULL) { - fprintf(stderr, "\tmemory allocation failed \n"); - fclose(fp); - return FALSE; - } - + *data = (void *)g_malloc0(len); *length = fread(*data, 1, (size_t)len, fp); if (*length != len) { fprintf(stderr, "\t[PNG_testsuite] fread failed \n"); @@ -114,11 +108,6 @@ static gboolean _read_file(char *path, void **data, size_t *length) fclose(fp); - if (*data == NULL) { - *length = 0; - return FALSE; - } - *length = (size_t)len; fprintf(stderr, "\t[PNG_testsuite] %s %zu read DONE\n", path, *length);