1 From c01a30a6821b243cb0f497b73bb5a7b7465b6aca Mon Sep 17 00:00:00 2001
2 From: Amarnath Valluri <amarnath.valluri@intel.com>
3 Date: Tue, 4 Aug 2015 13:04:45 +0300
4 Subject: [PATCH 17/18] libparted: Fix possible memory leaks
6 * libparted/fs/r/fat/resize.c(fat_convert_directory): Possible leak
7 of sub_old_dir_trav or sub_new_dir_trav in error case.
8 * libparted/fs/r/fat/resize.c(fat_construct_converted_tree ): Possible
9 leak of new_trav_info or old_trav_info in error case.
11 Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
12 Signed-off-by: Brian C. Lane <bcl@redhat.com>
13 (cherry picked from commit 4886bad13dd011ff56e1c46ff29e8067778c16fd)
15 libparted/fs/r/fat/resize.c | 11 +++++++++--
16 1 file changed, 9 insertions(+), 2 deletions(-)
18 diff --git a/libparted/fs/r/fat/resize.c b/libparted/fs/r/fat/resize.c
19 index 919acf0..b512576 100644
20 --- a/libparted/fs/r/fat/resize.c
21 +++ b/libparted/fs/r/fat/resize.c
22 @@ -177,10 +177,13 @@ fat_convert_directory (FatOpContext* ctx, FatTraverseInfo* old_trav,
23 && old_dir_entry->name [0] != '.') {
25 = fat_traverse_directory (old_trav, old_dir_entry);
26 + if (!sub_old_dir_trav) return 0;
28 = fat_traverse_directory (new_trav, new_dir_entry);
29 - if (!sub_old_dir_trav || !sub_new_dir_trav)
30 + if (!sub_new_dir_trav) {
31 + fat_traverse_complete (sub_old_dir_trav);
35 if (!fat_convert_directory (ctx, sub_old_dir_trav,
37 @@ -315,17 +318,21 @@ fat_construct_converted_tree (FatOpContext* ctx)
38 if (new_fs_info->fat_type == FAT_TYPE_FAT32) {
39 new_trav_info = fat_traverse_begin (ctx->new_fs,
40 new_fs_info->root_cluster, "\\");
41 + if (!new_trav_info) return 0;
42 old_trav_info = fat_traverse_begin (ctx->old_fs, FAT_ROOT,
45 fat_clear_root_dir (ctx->new_fs);
46 new_trav_info = fat_traverse_begin (ctx->new_fs, FAT_ROOT,
48 + if (!new_trav_info) return 0;
49 old_trav_info = fat_traverse_begin (ctx->old_fs,
50 old_fs_info->root_cluster, "\\");
52 - if (!new_trav_info || !old_trav_info)
53 + if (!old_trav_info) {
54 + fat_traverse_complete (new_trav_info);
57 if (!fat_convert_directory (ctx, old_trav_info, new_trav_info))