diff options
author | Daniel Golle <daniel@makrotopia.org> | 2021-08-14 18:15:54 +0100 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2021-08-14 18:53:16 +0100 |
commit | a77c4fac6f059e24257bf6fa810be03b4b9d7951 (patch) | |
tree | 2e9df887afdf26b02657a70e01b0cf3f67f995ba | |
parent | 68ae639148ca503681c1a69e977d0c952a4d2a40 (diff) | |
download | fstools-a77c4fac6f059e24257bf6fa810be03b4b9d7951.tar.gz |
ubi: fix resource leak in legacy codepath
I'm not even sure we are even using this 'ubi' tool anywhere.
Fix the resource leak reported by Coverity anyway.
Coverity CID: 1330289 Resource leak
Coverity CID: 1330290 Resource leak
Coverity CID: 1330291 Resource leak
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
-rw-r--r-- | ubi.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -150,9 +150,11 @@ static int main_detach(char *type) err = ubidetach(libubi, mtd); if (err) { ULOG_ERR("cannot detach \"%s\"", mtd); + libubi_close(libubi); return -1; } + libubi_close(libubi); return 0; } @@ -193,6 +195,7 @@ static int main_image(char *partition, char *image, char *overlay) err = mtd_find("rootfs_ubi", mtd); if (err) { ULOG_ERR("MTD partition '%s_ubi' not found\n", partition); + libubi_close(libubi); return -1; } @@ -202,18 +205,21 @@ static int main_image(char *partition, char *image, char *overlay) err = ubi_find(libubi, "rootfs_ubi", node); if (err) { ULOG_ERR("UBI volume '%s' not found\n", partition); + libubi_close(libubi); return -1; } err = ubidetach(libubi, mtd); if (err) { ULOG_ERR("cannot detach \"%s\"", mtd); + libubi_close(libubi); return -1; } err = ubiattach(libubi, mtd); if (err) { ULOG_ERR("cannot attach \"%s\"", mtd); + libubi_close(libubi); return -1; } @@ -221,24 +227,28 @@ static int main_image(char *partition, char *image, char *overlay) err = ubirmvol(libubi, node, overlay); if (err) { ULOG_ERR("cannot remove \"%s\"", node); + libubi_close(libubi); return -1; } } if (volume_find(libubi, partition, volume) < 0) { ULOG_ERR("UBI volume '%s' not found\n", partition); + libubi_close(libubi); return -1; } err = ubirsvol(libubi, node, partition, s.st_size); if (err) { ULOG_ERR("cannot resize \"%s\"", partition); + libubi_close(libubi); return -1; } err = ubiupdatevol(libubi, volume, image); if (err) { ULOG_ERR("cannot update \"%s\"", volume); + libubi_close(libubi); return -1; } @@ -246,6 +256,7 @@ static int main_image(char *partition, char *image, char *overlay) err = ubimkvol(libubi, node, overlay, 1); if (err) { ULOG_ERR("cannot make \"%s\"", overlay); + libubi_close(libubi); return -1; } } @@ -269,6 +280,7 @@ static int main_info(void) if (ubi_get_info(libubi, &info)) { ULOG_ERR("failed to get info\n"); + libubi_close(libubi); return -1; } |