xfs
[Top] [All Lists]

[PATCH 6/9] xfsdump: free suboptstrs if mlog_init1 fails

To: xfs@xxxxxxxxxxx
Subject: [PATCH 6/9] xfsdump: free suboptstrs if mlog_init1 fails
From: Eric Sandeen <sandeen@xxxxxxxxxx>
Date: Wed, 12 Nov 2014 12:57:15 -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>
suboptstrs was never freed on error paths.

Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
---
 common/mlog.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/common/mlog.c b/common/mlog.c
index b0135b9..f1fa12f 100644
--- a/common/mlog.c
+++ b/common/mlog.c
@@ -149,6 +149,7 @@ mlog_init1( intgen_t argc, char *argv[ ] )
        ix_t soix;
        size_t vsymcnt;
        intgen_t c;
+       bool_t retval = BOOL_FALSE;     /* Until proven otherwise */
 
        /* prepare an array of suboption token strings. this will be the
         * concatenation of the subsystem names with the verbosity symbols.
@@ -192,7 +193,7 @@ mlog_init1( intgen_t argc, char *argv[ ] )
                                         progname,
                                         c );
                                usage( );
-                               return BOOL_FALSE;
+                               goto out_free;
                        }
                        options = optarg;
                        while ( *options ) {
@@ -208,7 +209,7 @@ mlog_init1( intgen_t argc, char *argv[ ] )
                                                 progname,
                                                 c );
                                        usage( );
-                                       return BOOL_FALSE;
+                                       goto out_free;
                                }
                                ASSERT( ( ix_t )suboptix
                                        <
@@ -224,7 +225,7 @@ mlog_init1( intgen_t argc, char *argv[ ] )
                                                         c,
                                                mlog_ss_names[ suboptix ] );
                                                usage( );
-                                               return BOOL_FALSE;
+                                               goto out_free;
                                        }
                                        ssix = ( ix_t )suboptix;
                                        mlog_level_ss[ ssix ] =
@@ -238,7 +239,7 @@ mlog_init1( intgen_t argc, char *argv[ ] )
                                                         progname,
                                                         c );
                                                usage( );
-                                               return BOOL_FALSE;
+                                               goto out_free;
                                        }
                                        ssix = MLOG_SS_GEN;
                                        mlog_level_ss[ ssix ] =
@@ -251,7 +252,7 @@ mlog_init1( intgen_t argc, char *argv[ ] )
                                                 progname,
                                                 c );
                                        usage( );
-                                       return BOOL_FALSE;
+                                       goto out_free;
                                }
                        }
                        break;
@@ -267,8 +268,6 @@ mlog_init1( intgen_t argc, char *argv[ ] )
                }
        }
 
-       free( ( void * )suboptstrs );
-
        /* give subsystems not explicitly called out the "general" verbosity
         */
        for ( ssix = 0 ; ssix < MLOG_SS_CNT ; ssix++ ) {
@@ -301,7 +300,11 @@ mlog_init1( intgen_t argc, char *argv[ ] )
 
        mlog_qlockh = QLOCKH_NULL;
 
-       return BOOL_TRUE;
+       retval = BOOL_TRUE;
+
+out_free:
+       free( ( void * )suboptstrs );
+       return retval;
 }
 
 bool_t
-- 
1.7.1

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