tbm_module: Fix leak of fd
[platform/core/uifw/libtbm.git] / src / tbm_module.c
index 22dc061..b03d01a 100644 (file)
@@ -514,16 +514,22 @@ tbm_module_bind_native_display(tbm_module *module, void *native_display)
                                return TBM_ERROR_INVALID_OPERATION;
                        }
 
-                       // make the wayland server socket for sending the authenticated drm_fd to wayland clients.
-                       if (!tbm_drm_helper_wl_auth_server_init(native_display, fd, NULL, 0)) {
-                               TBM_ERR("error: tbm_drm_helper_wl_auth_server_init failed\n", module, native_display);
+                       if (tbm_drm_helper_is_render_node(fd)) {
+                               TBM_INFO("tbm_module has render node.");
                                close(fd);
-                               return TBM_ERROR_INVALID_OPERATION;
-                       }
-                       TBM_INFO("tbm creates a wayland socket for authentication of drm_fd.");
+                               error = TBM_ERROR_NONE;
+                       } else {
+                               // make the wayland server socket for sending the authenticated drm_fd to wayland clients.
+                               if (!tbm_drm_helper_wl_auth_server_init(native_display, fd, NULL, 0)) {
+                                       TBM_ERR("error: tbm_drm_helper_wl_auth_server_init failed\n", module, native_display);
+                                       close(fd);
+                                       return TBM_ERROR_INVALID_OPERATION;
+                               }
+                               TBM_INFO("tbm creates a wayland socket for authentication of drm_fd.");
 
-                       module->auth_wl_socket_created = 1;
-                       module->auth_fd = fd;
+                               module->auth_wl_socket_created = 1;
+                               module->auth_fd = fd;
+                       }
                } else {
                        TBM_INFO("tbm_module has no drm device.");
                        error = TBM_ERROR_NONE;
@@ -701,8 +707,8 @@ tbm_module_alloc_surface_data(tbm_module *module, int width, int height, int for
                                                                                           0,
                                                                                           (hal_tbm_error *)error);
        if (!surface_data->hal_surface) {
-               TBM_ERR("hal_tbm_bufmgr_alloc_surface failed.");
-               *error = TBM_ERROR_INVALID_OPERATION;
+               if (*error != TBM_ERROR_NOT_SUPPORTED) // do not print the error message when it is not supported.
+                       TBM_ERR("hal_tbm_bufmgr_alloc_surface failed.");
                free(surface_data);
                return NULL;
        }
@@ -821,7 +827,8 @@ tbm_module_alloc_bo_data_with_format(tbm_module *module, int format, int bo_idx,
                bo_data->hal_bo = hal_tbm_bufmgr_alloc_bo_with_format(module->hal_bufmgr,
                                                                                        format, bo_idx, width, height, bpp,
                                                                                        (hal_tbm_bo_memory_type)flags, (hal_tbm_error *)error);
-               TBM_GOTO_VAL_IF_FAIL(bo_data->hal_bo, failed);
+               if (!bo_data->hal_bo)
+                       goto failed;
                break;
 /* LCOV_EXCL_START */
        case TBM_MODULE_TYPE_TBM_BACKEND:
@@ -833,7 +840,8 @@ tbm_module_alloc_bo_data_with_format(tbm_module *module, int format, int bo_idx,
                }
 
                bo_data->backend_bo_data = bufmgr_func->bufmgr_alloc_bo_with_format(module->bufmgr_data, format, bo_idx, width, height, flags, error);
-               TBM_GOTO_VAL_IF_FAIL(bo_data->backend_bo_data, failed);
+               if (!bo_data->backend_bo_data)
+                       goto failed;
                break;
        case TBM_MODULE_TYPE_BUFMGR_BACKEND:
                TBM_WRN("!!WARNING: This backend interface will be DEPRECATED after Tizen 6.5.");
@@ -1290,7 +1298,7 @@ tbm_bo_data_map(tbm_bo_data *bo_data, int device, int opt, tbm_error_e *error)
        tbm_backend_bo_func *bo_func = NULL;
        tbm_bufmgr_backend backend = NULL;
        tbm_bo_handle bo_handle = (tbm_bo_handle)NULL;
-       hal_tbm_bo_handle hbo_handle;
+       hal_tbm_bo_handle hbo_handle = (hal_tbm_bo_handle)NULL;
 
        TBM_RETURN_VAL_SET_ERR_IF_FAIL(bo_data, (tbm_bo_handle)NULL, *error, TBM_ERROR_INVALID_PARAMETER);
        TBM_RETURN_VAL_SET_ERR_IF_FAIL(bo_data->module, (tbm_bo_handle)NULL, *error, TBM_ERROR_INVALID_PARAMETER);