dm: Fixes memory leak in setup_indexes function
PATCH 1/1 dm: Fixes memory leak in setup_indexes function
Sorry for multiple patches. This patch fixes memory leak in setup_indexes function where memory is allocated for indexes pointer by dm_vcalloc with the size of NODE_size and is not freed after that through the end of the function.
From 57da07e6847cedd14d54ba1675264377846a026c Mon Sep 17 00:00:00 2001
From: Shahzad Bangash <[email protected]>
Date: Tue, 3 Aug 2010 13:58:48 +0300
Subject: [PATCH] dm: Fixes memory leak in setup_indexes function "indexes" pointer in setup_indexes function is not freed.
--- drivers/md/dm-table.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
drivers/md/dm-table.c +4 -1
@@ -876,7 +876,7 @@ static int setup_indexes(struct dm_table *t) {int i;unsigned int total =0 ; -sector_t *indexes; +sector_t *indexes, *indexes_head;/* allocate the space for *all* the indexes */ for (i = t->depth -2 ; i >=0 ; i--) {
@@ -888,6 +888,8 @@ static int setup_indexes(struct dm_table *t)if (!indexes)return -ENOMEM ; + indexes_head = indexes; +/* set up internal nodes, bottom-up */ for (i = t->depth -2 ; i >=0 ; i--) { t->index[i] = indexes;
@@ -895,6 +897,7 @@ static int setup_indexes(struct dm_table *t)setup_btree_index (i, t); } +vfree (indexes_head);return 0 ; }
Signature · 1 line
1.6.3.3
Quoted 4 lines · Shahzad Hussain Bangash
Sorry for multiple patches. This patch fixes memory leak in
setup_indexesfunction where memory is allocated for indexes pointer bydm_vcallocwith the size ofNODE_sizeand is not freed after that through the end of the function.
There isn't a leak.
The 2nd loop's "t->index[i] = indexes;" takes ownership of the dm_vcalloc'd memory. dm_table_destroy() will later free that memory.
Your patch actually introduces a use after free bug.
Regards,
Mike