[libc-commits] [PATCH] D149793: [libc][rpc] Avoid leaking port in Server.h

Jon Chesterfield via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed May 3 15:15:27 PDT 2023


JonChesterfield created this revision.
JonChesterfield added a reviewer: jhuber6.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added projects: libc-project, All.
JonChesterfield requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149793

Files:
  libc/utils/gpu/loader/Server.h


Index: libc/utils/gpu/loader/Server.h
===================================================================
--- libc/utils/gpu/loader/Server.h
+++ libc/utils/gpu/loader/Server.h
@@ -28,6 +28,13 @@
   if (!port)
     return;
 
+  struct close {
+    using Port = decltype(port);
+    close(Port &port) : port(port) {}
+    ~close() { port->close(); }
+    Port &port;
+  } closer(port);
+
   switch (port->get_opcode()) {
   case __llvm_libc::rpc::Opcode::PRINT_TO_STDERR: {
     uint64_t str_size;
@@ -57,6 +64,5 @@
     port->recv([](__llvm_libc::rpc::Buffer *) { /* no-op */ });
     return;
   }
-  port->close();
 }
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149793.519276.patch
Type: text/x-patch
Size: 626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230503/95348e44/attachment-0001.bin>


More information about the libc-commits mailing list