tbm_module: Fix leak of fd
[platform/core/uifw/libtbm.git] / src / tbm_module.c
index 16beb7f..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;