Skip to contentSkip to conversation

Documentation/watchdog: close the fd when cmdline arg given

PATCH In review Devendra Naga 2 participants 3 messages May 14, 2012 – May 17, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Documentation/watchdog: close the fd when cmdline arg given

in the watchdog test code, the ioctl is performed on the watchdog device and just doing exit(0) so we leak a filedescripor.

---
 Documentation/watchdog/src/watchdog-test.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Documentation/watchdog/src/watchdog-test.c +6 -3
index 63fdc34..23084f2 100644
@@ -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;
 }
Signature · 1 line
1.7.9.5
#1 lore raw

Hi Devendra,

Quoted 4 lines

in the watchdog test code, the ioctl is performed on the watchdog device and just doing exit(0) so we leak a filedescripor.

Patch added to linux-watchdog-next.

Kind regards,
Wim.

#2 lore raw

Hello Wim,

Quoted 5 lines · Wim Van Sebroeck

Hi Devendra,

Quoted 3 lines

in the watchdog test code, the ioctl is performed on the watchdog device and just doing exit(0) so we leak a filedescripor.

Quoted 7 lines
Quoted 1 line

Patch added to linux-watchdog-next.

Kind regards,
Wim.

Thanks for taking the patch.

Actually we have a while (1) loop when ever user does ./watchdog-test, and if ctrl + c is done, we wont close the socket.
i will send the patch sooner to fix this on top this patch.

Thanks,
Devendra.