Skip to content

Commit

Permalink
Fix Python Shm Client Leak (#614)
Browse files Browse the repository at this point in the history
* Fix Python Shm Client Leak
  • Loading branch information
fpetrini15 authored May 7, 2024
1 parent a1a1f4e commit ef114b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/python/library/tritonclient/utils/shared_memory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,6 @@ def destroy_shared_memory_region(shm_handle):
SharedMemoryException
If unable to unlink the shared memory region.
"""

_raise_if_error(c_int(_cshm_shared_memory_region_destroy(shm_handle)))

shm_fd = c_int()
offset = c_uint64()
byte_size = c_uint64()
Expand All @@ -304,8 +301,13 @@ def destroy_shared_memory_region(shm_handle):
)
)
)
# It is safer to remove the shared memory key from the list before
# deleting the shared memory region because if the deletion should
# fail, a re-attempt could result in a segfault. Secondarily, if we
# fail to delete a region, we should not report it back to the user
# as a valid memory region.
mapped_shm_regions.remove(shm_key.value.decode("utf-8"))

_raise_if_error(c_int(_cshm_shared_memory_region_destroy(shm_handle)))
return


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <cstring>
#include <iostream>
#include <memory>

#include "shared_memory_handle.h"

Expand Down Expand Up @@ -132,8 +133,8 @@ GetSharedMemoryHandleInfo(
int
SharedMemoryRegionDestroy(void* shm_handle)
{
SharedMemoryHandle* handle =
reinterpret_cast<SharedMemoryHandle*>(shm_handle);
std::unique_ptr<SharedMemoryHandle> handle(
reinterpret_cast<SharedMemoryHandle*>(shm_handle));
void* shm_addr = reinterpret_cast<char*>(handle->base_addr_);
int status = munmap(shm_addr, handle->byte_size_);
if (status == -1) {
Expand All @@ -144,7 +145,6 @@ SharedMemoryRegionDestroy(void* shm_handle)
if (shm_fd == -1) {
return -5;
}

return 0;
}

Expand Down

0 comments on commit ef114b2

Please sign in to comment.