Documentation/watchdog: close the fd when cmdline arg given
authorDevendra Naga <devendra.aaru@gmail.com>
Mon, 14 May 2012 18:12:02 +0000 (23:42 +0530)
committerWim Van Sebroeck <wim@iguana.be>
Wed, 23 May 2012 14:27:40 +0000 (16:27 +0200)
in the watchdog test code, the ioctl is performed on the watchdog device
and just doing exit(0) so we leak a filedescripor.

Signed-off-by: Devendra Naga <devendra.aaru@gmail.com>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Documentation/watchdog/src/watchdog-test.c

index 63fdc34ceb984733416d7113caf336cb9eb2556e..23084f2212791fe6d376447042c52467a0b8af15 100644 (file)
@@ -47,18 +47,18 @@ int main(int argc, char *argv[])
            ioctl(fd, WDIOC_SETOPTIONS, &flags);
            fprintf(stderr, "Watchdog card disabled.\n");
            fflush(stderr);
-           exit(0);
+           goto end;
        } else if (!strncasecmp(argv[1], "-e", 2)) {
            flags = WDIOS_ENABLECARD;
            ioctl(fd, WDIOC_SETOPTIONS, &flags);
            fprintf(stderr, "Watchdog card enabled.\n");
            fflush(stderr);
-           exit(0);
+           goto end;
        } else {
            fprintf(stderr, "-d to disable, -e to enable.\n");
            fprintf(stderr, "run by itself to tick the card.\n");
            fflush(stderr);
-           exit(0);
+           goto end;
        }
     } else {
        fprintf(stderr, "Watchdog Ticking Away!\n");
@@ -69,4 +69,7 @@ int main(int argc, char *argv[])
        keep_alive();
        sleep(1);
     }
+end:
+    close(fd);
+    return 0;
 }