binder: fix memory leak [1/1]
authorchangqing.gao <changqing.gao@amlogic.com>
Thu, 4 Apr 2019 09:24:40 +0000 (17:24 +0800)
committerTao Zeng <tao.zeng@amlogic.com>
Wed, 17 Apr 2019 10:58:12 +0000 (03:58 -0700)
PD#TV-3541

Problem:
1.only vmalloc 4KB at first.
2.if user space need more memory, try to allocate a new vmalloc
  range with large size and move all related data to new place.
3.the first 4KB is not free when release this binder.

Solution:
free the first 4KB when release binder.

Verify:
R311

Change-Id: I4429de04a260671e4626b77ec340e47e436d5c8d
Signed-off-by: changqing.gao <changqing.gao@amlogic.com>
drivers/android/binder_alloc.c
drivers/android/binder_alloc.h

index 15f2872..dfb9a24 100644 (file)
@@ -838,6 +838,9 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
                goto err_get_vm_area_failed;
        }
        alloc->buffer = area->addr;
+#ifdef CONFIG_AMLOGIC_BINDER_VMALLOC
+       alloc->first_addr = area->addr;
+#endif
        alloc->user_buffer_offset =
                vma->vm_start - (uintptr_t)alloc->buffer;
        mutex_unlock(&binder_alloc_mmap_lock);
@@ -958,6 +961,8 @@ void binder_alloc_deferred_release(struct binder_alloc *alloc)
                vfree(alloc->buffer);
        #ifdef CONFIG_AMLOGIC_BINDER_VMALLOC
                free_back_buffer(alloc);
+               if (alloc->first_addr && alloc->first_addr != alloc->buffer)
+                       vfree(alloc->first_addr);
        #endif
        }
        mutex_unlock(&alloc->mutex);
index 592d4aa..2bda6b1 100644 (file)
@@ -113,6 +113,7 @@ struct binder_alloc {
 #ifdef CONFIG_AMLOGIC_BINDER_VMALLOC
        size_t mapped_size;
        void *back_buffer[MAX_BUFFER];
+       void *first_addr;
 #endif /* CONFIG_AMLOGIC_BINDER_VMALLOC */
        ptrdiff_t user_buffer_offset;
        struct list_head buffers;