different way of dealing with fd's so chmem <arg> <long list of files>

doesn't fail due to file descriptor leaks
This commit is contained in:
Ben Gras 2005-06-01 09:31:14 +00:00
parent a3d2f35993
commit 39a2fc72dd

View file

@ -36,7 +36,7 @@ char *argv[];
*/ */
char *p; char *p;
int fd, separate; int fd = -1, separate;
size_t s; size_t s;
long lsize, olddynam, newdynam, newtot, overflow; long lsize, olddynam, newdynam, newtot, overflow;
struct exec exec; struct exec exec;
@ -59,6 +59,7 @@ char *argv[];
while (--argc) { while (--argc) {
++argv; ++argv;
if(fd != -1) close(fd);
fd = open(*argv, O_RDWR); fd = open(*argv, O_RDWR);
if (fd < 0) { if (fd < 0) {
error("can't open", *argv); error("can't open", *argv);
@ -116,7 +117,6 @@ char *argv[];
} }
printf("%s: Stack+malloc area changed from %ld to %ld bytes.\n", printf("%s: Stack+malloc area changed from %ld to %ld bytes.\n",
*argv, olddynam, newdynam); *argv, olddynam, newdynam);
close(fd);
} }
return(0); return(0);
} }