Pārlūkot izejas kodu

LibIPC: Do not leak the Core::File fd by default

This prevents fd leaks when the user of the API forgets to pass
CloseAfterSending to IPC::File. Since we are calling leak_fd in the
constructor, we want it to also take care of closing.
Sebastian Zaha 2 gadi atpakaļ
vecāks
revīzija
88872ca42d

+ 2 - 3
Userland/Libraries/LibIPC/File.h

@@ -40,9 +40,8 @@ public:
     {
     {
     }
     }
 
 
-    template<typename... Args>
-    File(Core::File& file, Args... args)
-        : File(file.leak_fd(Badge<File> {}), args...)
+    explicit File(Core::File& file)
+        : File(file.leak_fd(Badge<File> {}), CloseAfterSending)
     {
     {
     }
     }
 
 

+ 2 - 2
Userland/Services/FileSystemAccessServer/ConnectionFromClient.cpp

@@ -81,7 +81,7 @@ void ConnectionFromClient::request_file_handler(i32 request_id, i32 window_serve
             dbgln("FileSystemAccessServer: Couldn't open {}, error {}", path, file.error());
             dbgln("FileSystemAccessServer: Couldn't open {}, error {}", path, file.error());
             async_handle_prompt_end(request_id, file.error().code(), Optional<IPC::File> {}, path);
             async_handle_prompt_end(request_id, file.error().code(), Optional<IPC::File> {}, path);
         } else {
         } else {
-            async_handle_prompt_end(request_id, 0, IPC::File(*file.release_value(), IPC::File::CloseAfterSending), path);
+            async_handle_prompt_end(request_id, 0, IPC::File(*file.release_value()), path);
         }
         }
     } else {
     } else {
         async_handle_prompt_end(request_id, EPERM, Optional<IPC::File> {}, path);
         async_handle_prompt_end(request_id, EPERM, Optional<IPC::File> {}, path);
@@ -138,7 +138,7 @@ void ConnectionFromClient::prompt_helper(i32 request_id, Optional<DeprecatedStri
 
 
             m_approved_files.set(user_picked_file.value(), new_permissions);
             m_approved_files.set(user_picked_file.value(), new_permissions);
 
 
-            async_handle_prompt_end(request_id, 0, IPC::File(*file.release_value(), IPC::File::CloseAfterSending), user_picked_file);
+            async_handle_prompt_end(request_id, 0, IPC::File(*file.release_value()), user_picked_file);
         }
         }
     } else {
     } else {
         async_handle_prompt_end(request_id, ECANCELED, Optional<IPC::File> {}, Optional<DeprecatedString> {});
         async_handle_prompt_end(request_id, ECANCELED, Optional<IPC::File> {}, Optional<DeprecatedString> {});

+ 1 - 1
Userland/Utilities/headless-browser.cpp

@@ -120,7 +120,7 @@ private:
         if (file.is_error())
         if (file.is_error())
             client().async_handle_file_return(file.error().code(), {}, request_id);
             client().async_handle_file_return(file.error().code(), {}, request_id);
         else
         else
-            client().async_handle_file_return(0, IPC::File(*file.value(), IPC::File::CloseAfterSending), request_id);
+            client().async_handle_file_return(0, IPC::File(*file.value()), request_id);
     }
     }
 
 
     void notify_server_did_finish_handling_input_event(bool) override { }
     void notify_server_did_finish_handling_input_event(bool) override { }