]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
wipefs: fix memory leak [coverity scan]
authorKarel Zak <kzak@redhat.com>
Wed, 27 Mar 2013 15:25:30 +0000 (16:25 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 27 Mar 2013 15:25:30 +0000 (16:25 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/wipefs.c

index 56024301e4bbdfbea0f29d37ea641f85415b41f0..156f2143da316d1d7af1c2a42fac91e9824e5caa 100644 (file)
@@ -216,7 +216,7 @@ get_desc_for_probe(struct wipe_desc *wp, blkid_probe pr)
 static blkid_probe
 new_probe(const char *devname, int mode)
 {
-       blkid_probe pr;
+       blkid_probe pr = NULL;
 
        if (!devname)
                return NULL;
@@ -227,8 +227,10 @@ new_probe(const char *devname, int mode)
                        goto error;
 
                pr = blkid_new_probe();
-               if (pr && blkid_probe_set_device(pr, fd, 0, 0))
+               if (pr && blkid_probe_set_device(pr, fd, 0, 0)) {
+                       close(fd);
                        goto error;
+               }
        } else
                pr = blkid_new_probe_from_filename(devname);
 
@@ -245,6 +247,7 @@ new_probe(const char *devname, int mode)
 
        return pr;
 error:
+       blkid_free_probe(pr);
        err(EXIT_FAILURE, _("error: %s: probing initialization failed"), devname);
        return NULL;
 }