From a77c4fac6f059e24257bf6fa810be03b4b9d7951 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sat, 14 Aug 2021 18:15:54 +0100 Subject: 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 --- ubi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ubi.c b/ubi.c index 54f67b8..f0dfc5c 100644 --- a/ubi.c +++ b/ubi.c @@ -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; } -- cgit v1.2.1