]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm/mdmon: fix coverity issue RESOURCE_LEAK
authorXiao Ni <xni@redhat.com>
Fri, 26 Jul 2024 07:14:08 +0000 (15:14 +0800)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Mon, 5 Aug 2024 09:11:59 +0000 (11:11 +0200)
Fix resource leak problem in mdmon.c

Signed-off-by: Xiao Ni <xni@redhat.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
mdmon.c

diff --git a/mdmon.c b/mdmon.c
index cae6384140c2870d4427d3be9b132202068cd39e..6e28b56e361b5e17cc2c2df0cab1efbfbac05940 100644 (file)
--- a/mdmon.c
+++ b/mdmon.c
@@ -456,22 +456,25 @@ static int mdmon(char *devnm, int must_fork, int takeover)
        if (must_fork) {
                if (pipe(pfd) != 0) {
                        pr_err("failed to create pipe\n");
+                       close_fd(&mdfd);
                        return 1;
                }
                switch(fork()) {
                case -1:
                        pr_err("failed to fork: %s\n", strerror(errno));
+                       close_fd(&mdfd);
                        return 1;
                case 0: /* child */
-                       close(pfd[0]);
+                       close_fd(&pfd[0]);
                        break;
                default: /* parent */
-                       close(pfd[1]);
+                       close_fd(&pfd[1]);
                        if (read(pfd[0], &status, sizeof(status)) != sizeof(status)) {
                                wait(&status);
                                status = WEXITSTATUS(status);
                        }
-                       close(pfd[0]);
+                       close_fd(&pfd[0]);
+                       close_fd(&mdfd);
                        return status;
                }
        } else