[libc-commits] [libc] [libc] Move the pointer to pin off the stack to the heap (PR #74118)

Jon Chesterfield via libc-commits libc-commits at lists.llvm.org
Fri Dec 1 09:55:27 PST 2023


================
@@ -471,12 +471,13 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
     handle_error(err);
 
   // Pin some memory we can use to obtain the address of the rpc client.
-  void **rpc_client_storage = new void *;
+  void *rpc_client_storage = malloc(sizeof(void *));
   void *rpc_client_host = nullptr;
   if (hsa_status_t err =
           hsa_amd_memory_lock(&rpc_client_storage, sizeof(void *),
                               /*agents=*/nullptr, 0, &rpc_client_host))
     handle_error(err);
+  free(rpc_client_storage);
----------------
JonChesterfield wrote:

This can't be right. If you allocated some memory, and then locked it, you still need to leave that memory allocated until you're finished with it. Free should be after the unlock. Nested lifetimes and all that.

https://github.com/llvm/llvm-project/pull/74118


More information about the libc-commits mailing list