Remove out of memory related code by using glib APIs 83/230983/16 accepted/tizen/unified/20200429.032902 submit/tizen/20200428.070655
authorhj kim <backto.kim@samsung.com>
Thu, 16 Apr 2020 09:32:00 +0000 (18:32 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 28 Apr 2020 06:24:23 +0000 (15:24 +0900)
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

12 files changed:
bmp/test/mm_util_bmp_testsuite.c
common/mm_util_image.c
gif/mm_util_gif.c
gif/test/mm_util_gif_testsuite.c
imgcv/mm_util_imgcv.cpp
imgp/mm_util_imgp.c
imgp/test/mm_util_imgp_testsuite.c
jpeg/mm_util_jpeg.c
jpeg/test/mm_util_jpeg_testsuite.c
magick/mm_util_magick.c
packaging/libmm-utility.spec
png/test/mm_util_png_testsuite.c

index 03754f0b896b458aef3bdcfcd3ff0222f9a52593..1676fd46d92dcf35bbd48e6d690403a224f2622a 100644 (file)
@@ -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;
index c3b88f5155e5be127f54ceebe33b8756b8cd7ebe..8a891818ed25e49e204374bf3e90ac916f2ca101 100755 (executable)
@@ -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);
 }
index 63dd6886c57d1abe4ca1d2bd14d9589f30d72fcc..8a66f43711dfa1ce9ca65bee2cfe4d59b42d491d 100644 (file)
@@ -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);
 }
index e8eefd298251b86b3d6300cb4968eedbace0863f..238f28b08e3c80c8b9a5cc1bc7aabf4a996a955f 100644 (file)
@@ -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++;
        }
index b9b589e9aaf932f87bfdca09038e879611b7178f..5f36ef342e62fb437b44b4831f6fd64156ea58b3 100755 (executable)
@@ -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();
 
index b0d5c8dcd2157ac96b1f2231360b63bd99742599..3049f2f8936abb9867e0dbc3d898b675ad8e0ce4 100644 (file)
@@ -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;
index 7f1b6549f253b2cbfadfadf8ae3b95ca8dddb9cb..7589011c7e6f1d1b3a830cf2b00b1809c0ccffff 100644 (file)
@@ -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);
index 9f21c120094d1a7c1494497ee25f189896625e1a..284e17a188fa2aa91a434402fd3fd2af00cd31b9 100644 (file)
@@ -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 */
index f0b92b00da5f3a7bf4d3c3c9b6bf67f96cd32cf3..f97880d6e40ee0516a7d675372051a098ad8b99a 100644 (file)
@@ -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);
index df55d40d2e0a3128d2ea1d2c05ea6485294bd1a9..f163c9505d940b91a3b8d9e96f8acd6aca328068 100644 (file)
@@ -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();
 
index 7e9d005d9d41aaa7745c655eeb059975fc6da3eb..63bc55cadeb19816bb79e004ab9edf5dd1cd202b 100644 (file)
@@ -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
index a2b18231d5a3c44dfc3c3b206841b4b736cc2e8b..c484a156c4ca6ef6b5329b0ffd2598905b5a6a5f 100644 (file)
@@ -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);