Fix a leak. (Thanks Bruce, this was a bonehead mistake on my part :).)

Submitted by:	Bruce Evans
This commit is contained in:
Sean Eric Fagan 2000-02-15 20:25:47 +00:00
parent 2c6610f343
commit 05d5ca3587

View File

@ -115,10 +115,12 @@ get_syscall(const char *name) {
char *
get_string(int procfd, void *offset, int max) {
char *buf;
int size, len, c;
int size, len, c, fd;
FILE *p;
if ((p = fdopen(procfd, "r")) == NULL)
if ((fd = dup(procfd)) == -1)
err(1, "dup");
if ((p = fdopen(fd, "r")) == NULL)
err(1, "fdopen");
buf = malloc( size = (max ? max : 64 ) );
len = 0;
@ -130,15 +132,18 @@ get_string(int procfd, void *offset, int max) {
break;
}
if (len == size) {
char *tmp = buf;
char *tmp;
tmp = realloc(buf, size+64);
if (tmp == NULL) {
buf[len] = 0;
fclose(p);
return buf;
}
size += 64;
buf = tmp;
}
}
fclose(p);
return buf;
}