Skip to content

Commit adb9743

Browse files
Qi Zhenggregkh
authored andcommitted
binder: fix memory leak in binder_init()
In binder_init(), the destruction of binder_alloc_shrinker_init() is not performed in the wrong path, which will cause memory leaks. So this commit introduces binder_alloc_shrinker_exit() and calls it in the wrong path to fix that. Signed-off-by: Qi Zheng <[email protected]> Acked-by: Carlos Llamas <[email protected]> Fixes: f2517eb ("android: binder: Add global lru shrinker to binder") Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 63b93e7 commit adb9743

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

drivers/android/binder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6617,6 +6617,7 @@ static int __init binder_init(void)
66176617

66186618
err_alloc_device_names_failed:
66196619
debugfs_remove_recursive(binder_debugfs_dir_entry_root);
6620+
binder_alloc_shrinker_exit();
66206621

66216622
return ret;
66226623
}

drivers/android/binder_alloc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,12 @@ int binder_alloc_shrinker_init(void)
10871087
return ret;
10881088
}
10891089

1090+
void binder_alloc_shrinker_exit(void)
1091+
{
1092+
unregister_shrinker(&binder_shrinker);
1093+
list_lru_destroy(&binder_alloc_lru);
1094+
}
1095+
10901096
/**
10911097
* check_buffer() - verify that buffer/offset is safe to access
10921098
* @alloc: binder_alloc for this proc

drivers/android/binder_alloc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ extern struct binder_buffer *binder_alloc_new_buf(struct binder_alloc *alloc,
129129
int pid);
130130
extern void binder_alloc_init(struct binder_alloc *alloc);
131131
extern int binder_alloc_shrinker_init(void);
132+
extern void binder_alloc_shrinker_exit(void);
132133
extern void binder_alloc_vma_close(struct binder_alloc *alloc);
133134
extern struct binder_buffer *
134135
binder_alloc_prepare_to_free(struct binder_alloc *alloc,

0 commit comments

Comments
 (0)