buffer: not allow adding handler twice 95/170995/2
authorBoram Park <boram1288.park@samsung.com>
Fri, 23 Feb 2018 06:37:50 +0000 (15:37 +0900)
committerBoram Park <boram1288.park@samsung.com>
Sun, 25 Feb 2018 23:27:57 +0000 (08:27 +0900)
Change-Id: I385a17820ff81f527ab21e0d01dbe07e274dace0

src/tdm_buffer.c

index 5d501b0..31e8c41 100644 (file)
@@ -120,7 +120,7 @@ tdm_buffer_add_release_handler(tbm_surface_h buffer,
                                                           tdm_buffer_release_handler func, void *user_data)
 {
        tdm_buffer_info *buf_info;
-       tdm_buffer_func_info *func_info;
+       tdm_buffer_func_info *func_info = NULL;
 
        TDM_RETURN_VAL_IF_FAIL(buffer != NULL, TDM_ERROR_INVALID_PARAMETER);
        TDM_RETURN_VAL_IF_FAIL(func != NULL, TDM_ERROR_INVALID_PARAMETER);
@@ -128,6 +128,13 @@ tdm_buffer_add_release_handler(tbm_surface_h buffer,
        buf_info = tdm_buffer_get_info(buffer);
        TDM_RETURN_VAL_IF_FAIL(buf_info != NULL, TDM_ERROR_OUT_OF_MEMORY);
 
+       LIST_FOR_EACH_ENTRY(func_info, &buf_info->release_funcs, link) {
+               if (func_info->release_func == func && func_info->user_data == user_data) {
+                       TDM_ERR("can't add twice");
+                       return TDM_ERROR_BAD_REQUEST;
+               }
+       }
+
        func_info = calloc(1, sizeof(tdm_buffer_func_info));
        TDM_RETURN_VAL_IF_FAIL(func_info != NULL, TDM_ERROR_OUT_OF_MEMORY);
 
@@ -240,6 +247,13 @@ tdm_buffer_add_destroy_handler(tbm_surface_h buffer,
        buf_info = tdm_buffer_get_info(buffer);
        TDM_RETURN_VAL_IF_FAIL(buf_info != NULL, TDM_ERROR_OUT_OF_MEMORY);
 
+       LIST_FOR_EACH_ENTRY(func_info, &buf_info->destroy_funcs, link) {
+               if (func_info->destroy_func == func && func_info->user_data == user_data) {
+                       TDM_ERR("can't add twice");
+                       return TDM_ERROR_BAD_REQUEST;
+               }
+       }
+
        func_info = calloc(1, sizeof(tdm_buffer_func_info));
        TDM_RETURN_VAL_IF_FAIL(func_info != NULL, TDM_ERROR_OUT_OF_MEMORY);