xfs
[Top] [All Lists]

[PATCH 7/9] xfsdump: free allocated persistent paths

To: xfs@xxxxxxxxxxx
Subject: [PATCH 7/9] xfsdump: free allocated persistent paths
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Wed, 12 Nov 2014 12:57:16 -0600
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1415818638-32700-1-git-send-email-sandeen@xxxxxxxxxx>
References: <1415818638-32700-1-git-send-email-sandeen@xxxxxxxxxx>
"perspath" gets allocated by open_pathalloc, and haphazardly
freed at best; almost never on errors, often not on success.

While we're in there, fix a few leaked fd's as well.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---
 restore/content.c |    2 ++
 restore/inomap.c  |   11 +++++++++++
 restore/tree.c    |    9 +++++++++
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/restore/content.c b/restore/content.c
index cfcf94d..c99aed7 100644
--- a/restore/content.c
+++ b/restore/content.c
@@ -1342,6 +1342,7 @@ content_init( intgen_t argc, char *argv[ ], size64_t vmsz 
)
                      "could not open/create persistent state file %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return BOOL_FALSE;
        }
 
@@ -1356,6 +1357,7 @@ content_init( intgen_t argc, char *argv[ ], size64_t vmsz 
)
                      "could not map persistent state file hdr %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return BOOL_FALSE;
        }
 
diff --git a/restore/inomap.c b/restore/inomap.c
index 562492e..1976017 100644
--- a/restore/inomap.c
+++ b/restore/inomap.c
@@ -217,6 +217,7 @@ inomap_restore_pers( drive_t *drivep,
                      "could not open %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return RV_ERROR;
        }
 
@@ -233,6 +234,8 @@ inomap_restore_pers( drive_t *drivep,
                      "unable to map %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               close(fd);
+               free(perspath);
                return RV_ERROR;
        }
 
@@ -363,6 +366,7 @@ inomap_sync_pers( char *hkdir )
        perspath = open_pathalloc( hkdir, PERS_NAME, 0 );
        pers_fd = open( perspath, O_RDWR );
        if ( pers_fd < 0 ) {
+               free(perspath);
                return BOOL_TRUE;
        }
 
@@ -377,6 +381,8 @@ inomap_sync_pers( char *hkdir )
                      "unable to map %s hdr: %s\n"),
                      perspath,
                      strerror( errno ));
+               close(pers_fd);
+               free(perspath);
                return BOOL_FALSE;
        }
 
@@ -398,9 +404,14 @@ inomap_sync_pers( char *hkdir )
                      "unable to map %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               close(pers_fd);
+               free(perspath);
                return BOOL_FALSE;
        }
 
+       close(pers_fd);
+       free(perspath);
+
        /* correct the next pointers
         */
        for ( hnkp = roothnkp
diff --git a/restore/tree.c b/restore/tree.c
index 21d3880..011fa44 100644
--- a/restore/tree.c
+++ b/restore/tree.c
@@ -420,6 +420,7 @@ tree_init( char *hkdir,
                      "could not open %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return BOOL_FALSE;
        }
 
@@ -435,6 +436,7 @@ tree_init( char *hkdir,
                      "unable to map %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return BOOL_FALSE;
        }
 
@@ -443,9 +445,12 @@ tree_init( char *hkdir,
         */
        ok = hash_init( vmsz / HASHSZ_PERVM, dircnt, nondircnt, perspath );
        if ( ! ok ) {
+               free(perspath);
                return BOOL_FALSE;
        }
 
+       free(perspath);
+
        /* initialize the node abstraction. let it's use of backing store
         * begin immediately after the hash abstraction. give it the remainder
         * of vm.
@@ -595,6 +600,7 @@ tree_sync( char *hkdir,
                      "could not open %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return BOOL_FALSE;
        }
 
@@ -610,6 +616,7 @@ tree_sync( char *hkdir,
                      "unable to map %s: %s\n"),
                      perspath,
                      strerror( errno ));
+               free(perspath);
                return BOOL_FALSE;
        }
 
@@ -632,9 +639,11 @@ tree_sync( char *hkdir,
         */
        ok = hash_sync( perspath );
        if ( ! ok ) {
+               free(perspath);
                return BOOL_FALSE;
        }
 
+       free(perspath);
        /* synchronize with the node abstraction.
         */
        ASSERT( persp->p_hashsz <= ( size64_t )( OFF64MAX - ( off64_t )PERSSZ));
-- 
1.7.1

<Prev in Thread] Current Thread [Next in Thread>