n = fread(buffer, 1, size, fd);
if (n != size) {
mm_util_error("file read failed");
- free(buffer);
+ BMP_SAFE_FREE(buffer);
fclose(fd);
return NULL;
}
void __bitmap_destroy(void *bitmap)
{
- free(bitmap);
+ BMP_SAFE_FREE(bitmap);
}
static int __read_bmp(mm_util_bmp_data *decoded, const char *filename, void *memory, unsigned long long src_size)
cleanup:
bmp_finalise(&bmp);
if (filename)
- free(data);
+ BMP_SAFE_FREE(data);
return res;
}
if ((OutputColorMap = GifMakeMapObject(ColorMapSize, NULL)) == NULL) {
mm_util_error("could not map object");
RGB_FREE(red, green, blue);
- free(OutputBuffer);
+ MMUTIL_SAFE_FREE(OutputBuffer);
mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
if (GifQuantizeBuffer(encoded->frames[i]->width, encoded->frames[i]->height, &ColorMapSize, red, green, blue, OutputBuffer, OutputColorMap->Colors) == GIF_ERROR) {
mm_util_error("could not quantize buffer");
RGB_FREE(red, green, blue);
- free(OutputBuffer);
+ MMUTIL_SAFE_FREE(OutputBuffer);
GifFreeMapObject(OutputColorMap);
mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
/* encode OutputBuffer to GifFile */
if (__save_buffer_to_gif(encoded->GifFile, OutputBuffer, OutputColorMap, encoded->frames[i]) != MM_UTIL_ERROR_NONE) {
mm_util_error("save_buffer_to_gif is failed");
- free(OutputBuffer);
+ MMUTIL_SAFE_FREE(OutputBuffer);
GifFreeMapObject(OutputColorMap);
mm_util_encode_close_gif(encoded);
return MM_UTIL_ERROR_INVALID_OPERATION;
}
- free(OutputBuffer);
+ MMUTIL_SAFE_FREE(OutputBuffer);
GifFreeMapObject(OutputColorMap);
encoded->current_count++;
}
goto SUCCESS;
FAIL:
- if (gif_image->intermediate_image) {
- free(gif_image->intermediate_image);
- gif_image->intermediate_image = NULL;
- }
+ if (gif_image->intermediate_image)
+ MMUTIL_SAFE_FREE(gif_image->intermediate_image);
+
gif_image->intermediate_image_size = 0;
COLORMAP_FREE(gif_image->image_desc.ColorMap);
SUCCESS:
int ret = _mm_util_imgcv_init(handle, width, height);
if (ret != MM_UTIL_ERROR_NONE) {
_mm_util_imgcv_uninit(handle);
- free(handle);
- handle = NULL;
+ MMUTIL_SAFE_FREE(handle);
mm_util_error("#ERROR#: Fail to mm_util_imgcv_init: ret=%d", ret);
ret = _mm_util_imgcv_set_buffer(handle, image_buffer);
if (ret != MM_UTIL_ERROR_NONE) {
_mm_util_imgcv_uninit(handle);
- free(handle);
- handle = NULL;
+ MMUTIL_SAFE_FREE(handle);
mm_util_error("#ERROR#: Fail to mm_util_imgcv_set_buffer: ret=%d", ret);
ret = _mm_util_imgcv_calculate_hist(handle, r_color, g_color, b_color);
if (ret != MM_UTIL_ERROR_NONE) {
_mm_util_imgcv_uninit(handle);
- free(handle);
- handle = NULL;
+ MMUTIL_SAFE_FREE(handle);
mm_util_error("#ERROR#: Fail to mm_util_imgcv_calculate_hist: ret=%d", ret);
_mm_util_imgcv_uninit(handle);
- free(handle);
- handle = NULL;
+ MMUTIL_SAFE_FREE(handle);
mm_util_debug("Leave mm_util_cv_extract_representative_color");