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
}
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");
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);
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++;
}
out:
g_free(g_path);
- SAFE_FREE(g_readed_data);
+ g_free(g_readed_data);
SAFE_IMAGE_FREE(g_decoded_data);
return 0;
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;
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;
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.
*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;
}
/* 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);
}
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)
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;
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++) {
}
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);
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;
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;
}
}
/* 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;
}
{
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;
g_free(gif_file->filename);
MMUTIL_SAFE_FREE(gif_file->io_buf.buf);
- MMUTIL_SAFE_FREE(gif_file);
+ g_free(gif_file);
}
}
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");
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);
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++;
}
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;
ERROR:
__mm_util_imgcv_uninit(handle);
- MMUTIL_SAFE_FREE(handle);
+ g_free(handle);
mm_util_fleave();
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,
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();
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) {
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();
_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) {
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();
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;
__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: {
}
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;
}
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");
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);
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);
}
}
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 {
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(...); */
}
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 */
}
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");
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);
}
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;
}
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();
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
}
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");
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);