Skip to contentSkip to conversation

xfs_db: free field list when failing out of fuzz

PATCH In review Darrick J. Wong 2 participants 2 messages Aug 5, 2017 – Aug 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_db: free field list when failing out of fuzz

Fix a missed opportunity to free the field list when we fail out of the fuzz command by refactoring the error clauses to use a common cleanup clause.

Fixes-coverity-id: 1416141

---
 db/fuzz.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
db/fuzz.c +4 -5
index a9b1577..76dbf94 100644
@@ -400,7 +400,7 @@ fuzz_struct(
 			break;
 	if (fc->fn == NULL) {
 		dbprintf(_("Unknown fuzz command '%s'.\n"), argv[1]);
-		return;
+		goto out_free;
 	}
 
 	/* if we're a root field type, go down 1 layer to get field list */
@@ -412,9 +412,8 @@ fuzz_struct(
 
 	/* run down the field list and set offsets into the data */
 	if (!flist_parse(fields, fl, iocur_top->data, 0)) {
-		flist_free(fl);
 		dbprintf(_("parsing error\n"));
-		return;
+		goto out_free;
 	}
 
 	sfl = fl;
@@ -447,8 +446,7 @@ fuzz_struct(
 	success = fc->fn(iocur_top->data, sfl->offset, bit_length);
 	if (!success) {
 		dbprintf(_("unable to fuzz field '%s'\n"), argv[0]);
-		flist_free(fl);
-		return;
+		goto out_free;
 	}
 
 	/* Write the fuzzed value back */
@@ -456,5 +454,6 @@ fuzz_struct(
 
 	flist_print(fl);
 	print_flist(fl);
+out_free:
 	flist_free(fl);
 }