From 39a2fc72ddf8a54ed732380ee1f910f26ff5c848 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 1 Jun 2005 09:31:14 +0000 Subject: [PATCH] different way of dealing with fd's so chmem doesn't fail due to file descriptor leaks --- commands/simple/chmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/simple/chmem.c b/commands/simple/chmem.c index 07da64c0d..3eb00c6db 100755 --- a/commands/simple/chmem.c +++ b/commands/simple/chmem.c @@ -36,7 +36,7 @@ char *argv[]; */ char *p; - int fd, separate; + int fd = -1, separate; size_t s; long lsize, olddynam, newdynam, newtot, overflow; struct exec exec; @@ -59,6 +59,7 @@ char *argv[]; while (--argc) { ++argv; + if(fd != -1) close(fd); fd = open(*argv, O_RDWR); if (fd < 0) { error("can't open", *argv); @@ -116,7 +117,6 @@ char *argv[]; } printf("%s: Stack+malloc area changed from %ld to %ld bytes.\n", *argv, olddynam, newdynam); - close(fd); } return(0); }