fix memory leak of 'nal_unit' and rename it 80/257880/2 accepted/tizen/unified/20210509.123858 submit/tizen/20210507.053543
authorjiyong.min <jiyong.min@samsung.com>
Thu, 6 May 2021 00:30:18 +0000 (09:30 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 7 May 2021 00:21:20 +0000 (09:21 +0900)
Change-Id: I5f81e0e3d28f663d6e3cb29b6f898d602dad59b5

packaging/libheif.spec
src/heif_itemtable.c
test/test.sh

index d0baed6..3cb496d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libheif
 Summary:    Multimedia Framework Library for HEIF(ISO/IEC 23008-12) image
-Version:    0.0.2
+Version:    0.0.3
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
index 6eee72a..03ca050 100644 (file)
@@ -104,6 +104,7 @@ typedef struct {
 
 static const uint8_t START_CODE[START_CODE_LEN] = { 0, 0, 0, 1 };      // start_code is 0x00000001
 
+static bool __is_valid_heif_buffer(heif_buffer_t *heif_buffer);
 static gint __compare_item_type(gconstpointer a, gconstpointer b);
 static gint __compare_image_item_id(gconstpointer data, gconstpointer user_data);
 static gint __compare_iloc_item_id(gconstpointer data, gconstpointer user_data);
@@ -335,7 +336,7 @@ int heif_itemtable_get_grid_info(heif_image_item_h image_item, unsigned int *row
 int heif_itemtable_get_coded_data(heif_itemtable_h handle, heif_image_item_h image_item, heif_buffer_t **coded_data)
 {
        _image_item_t *_image_item = (_image_item_t *)image_item;
-       heif_buffer_t *nal_unit = NULL;
+       heif_buffer_t *codec_config = NULL;
        heif_buffer_t *mdat = NULL;
        size_t read_n = 0;
 
@@ -343,37 +344,31 @@ int heif_itemtable_get_coded_data(heif_itemtable_h handle, heif_image_item_h ima
        heif_retvm_if_failed(image_item, LIBHEIF_ERROR_INVALID_PARAMETER, "invalid image_item");
        heif_retvm_if_failed(coded_data, LIBHEIF_ERROR_INVALID_PARAMETER, "invalid coded_data");
 
-       nal_unit = g_new0(heif_buffer_t, 1);
-       nal_unit->data = _image_item->hvc_config.nal_unit.data;
-       nal_unit->size = _image_item->hvc_config.nal_unit.size;
+       codec_config = &(_image_item->hvc_config.nal_unit);
+       heif_retvm_if_failed(__is_valid_heif_buffer(codec_config), LIBHEIF_ERROR_INVALID_PARAMETER, "invalid codec_config");
 
-       if (!nal_unit->data || nal_unit->size == 0) {
-               heif_error("nal_unit: %p, nal_unit: %zu", nal_unit->data, nal_unit->size);
-               g_free(nal_unit);
-               return LIBHEIF_ERROR_INVALID_PARAMETER;
-       }
 #ifdef __DEBUG_CODEC_CONFIG
        {
                size_t i = 0;
-               for (i = 0; i < nal_unit->size; i++)
-                       heif_error("nal_unit: %x", nal_unit->data[i]);
+               for (i = 0; i < codec_config->size; i++)
+                       heif_error("codec_config: %x", codec_config->data[i]);
        }
 #endif
 
        mdat = g_new0(heif_buffer_t, 1);
-       mdat->size = nal_unit->size + _image_item->size;
+       mdat->size = codec_config->size + _image_item->size;
        mdat->data = (uint8_t *)g_malloc0(mdat->size);
 
-       // attach nal_unit in front of media
-       memcpy(mdat->data, nal_unit->data, nal_unit->size);
-       memcpy(mdat->data + nal_unit->size, START_CODE, START_CODE_LEN);
+       // put the codec_config and the start_code in front of media
+       memcpy(mdat->data, codec_config->data, codec_config->size);
+       memcpy(mdat->data + codec_config->size, START_CODE, START_CODE_LEN);
 
        read_n = _image_item->size - START_CODE_LEN;
 
        // read media
        if (heif_source_read_at(((heif_itemtable_t *)handle)->source,
                                                        _image_item->offset + START_CODE_LEN,
-                                                       mdat->data + nal_unit->size + START_CODE_LEN,
+                                                       mdat->data + codec_config->size + START_CODE_LEN,
                                                        read_n) != read_n) {
                heif_error("heif_source_read_at fail");
                heif_buffer_destroy(mdat);
@@ -503,6 +498,15 @@ void heif_buffer_destroy(heif_buffer_t *buffer)
        g_free(buffer);
 }
 
+static bool __is_valid_heif_buffer(heif_buffer_t *heif_buffer)
+{
+       heif_retvm_if_failed(heif_buffer, false, "invalid heif_buffer");
+       heif_retvm_if_failed(heif_buffer->data, false, "invalid heif_buffer data");
+       heif_retvm_if_failed(heif_buffer->size > 0, false, "invalid heif_buffer size");
+
+       return true;
+}
+
 static gint __compare_item_type(gconstpointer a, gconstpointer b)
 {
        uint32_t item_type = (uint32_t)GPOINTER_TO_UINT(a);
index 90dfc35..7d0dc9a 100755 (executable)
@@ -18,7 +18,7 @@
 
 @echo off
 # VERSION should be same with library version.
-VERSION=0.0.1
+VERSION=0.0.3
 ARM=armv7l
 X86=i586
 AARCH64=aarch64