bcachefs: Fix a memory leak
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 27 Feb 2022 16:57:42 +0000 (11:57 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:26 +0000 (17:09 -0400)
This fixes a regression from "bcachefs: Heap allocate printbufs" -
bch2_sb_field_validate() was leaking an error string.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/super-io.c

index c616ce5ed194824c4c13a37fb85ff7eab06d035c..31b175a8fcd0767d007f0edf0c2799243d8636de 100644 (file)
@@ -1423,24 +1423,25 @@ static const struct bch_sb_field_ops *bch2_sb_field_ops[] = {
 };
 
 static int bch2_sb_field_validate(struct bch_sb *sb, struct bch_sb_field *f,
-                                 struct printbuf *orig_err)
+                                 struct printbuf *err)
 {
        unsigned type = le32_to_cpu(f->type);
-       struct printbuf err = *orig_err;
+       struct printbuf field_err = PRINTBUF;
        int ret;
 
        if (type >= BCH_SB_FIELD_NR)
                return 0;
 
-       pr_buf(&err, "Invalid superblock section %s: ", bch2_sb_fields[type]);
-
-       ret = bch2_sb_field_ops[type]->validate(sb, f, &err);
+       ret = bch2_sb_field_ops[type]->validate(sb, f, &field_err);
        if (ret) {
-               pr_newline(&err);
-               bch2_sb_field_to_text(&err, sb, f);
-               *orig_err = err;
+               pr_buf(err, "Invalid superblock section %s: %s",
+                      bch2_sb_fields[type],
+                      field_err.buf);
+               pr_newline(err);
+               bch2_sb_field_to_text(err, sb, f);
        }
 
+       printbuf_exit(&field_err);
        return ret;
 }