You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/06/20 15:40:24 UTC

[GitHub] [arrow] maxburke commented on a change in pull request #7480: ARROW-9176: [Rust] Fix for memory leaks in Arrow allocator

maxburke commented on a change in pull request #7480:
URL: https://github.com/apache/arrow/pull/7480#discussion_r443139838



##########
File path: rust/arrow/src/memory.rs
##########
@@ -150,25 +150,32 @@ pub fn allocate_aligned(size: usize) -> *mut u8 {
 }
 
 pub unsafe fn free_aligned(ptr: *mut u8, size: usize) {
-    if size != 0x00 && ptr != BYPASS_PTR.as_ptr() {
+    if ptr != BYPASS_PTR.as_ptr() {
         std::alloc::dealloc(ptr, Layout::from_size_align_unchecked(size, ALIGNMENT));
     }
 }
 
 pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, new_size: usize) -> *mut u8 {
     if ptr == BYPASS_PTR.as_ptr() {
-        allocate_aligned(new_size)
-    } else {
-        let new_ptr = std::alloc::realloc(
-            ptr,
-            Layout::from_size_align_unchecked(old_size, ALIGNMENT),
-            new_size,
-        );
-        if !new_ptr.is_null() && new_size > old_size {
-            new_ptr.add(old_size).write_bytes(0, new_size - old_size);
-        }
-        new_ptr
+        return allocate_aligned(new_size);
+    }
+
+    if new_size == 0 {
+        free_aligned(ptr, old_size);
+        return BYPASS_PTR.as_ptr();

Review comment:
       What kind of test are you looking for? Running valgrind on the tests to validate there are no leaked blocks?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org