From 1b72d60eddaf08f2b32c8cb2f52b32be132c9b36 Mon Sep 17 00:00:00 2001 From: "changqing.gao" Date: Thu, 4 Apr 2019 17:24:40 +0800 Subject: [PATCH] binder: fix memory leak [1/1] 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 --- drivers/android/binder_alloc.c | 5 +++++ drivers/android/binder_alloc.h | 1 + 2 files changed, 6 insertions(+) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index 15f287250940..dfb9a24f030c 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -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); diff --git a/drivers/android/binder_alloc.h b/drivers/android/binder_alloc.h index 592d4aa98945..2bda6b16584f 100644 --- a/drivers/android/binder_alloc.h +++ b/drivers/android/binder_alloc.h @@ -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;