87 lines
2.5 KiB
Text
87 lines
2.5 KiB
Text
$NetBSD: patch-ab,v 1.1 2004/03/08 18:57:43 hubertf Exp $
|
|
|
|
This patch tries to plug the file descriptor leak in driftnet 0.1.6.
|
|
It's probably not perfect, but better than nothing.
|
|
|
|
- Hubert Feyrer <hubertf@NetBSD.org>
|
|
|
|
--- img.c.orig Tue Jul 9 21:26:41 2002
|
|
+++ img.c Sun Mar 7 10:44:27 2004
|
|
@@ -14,6 +14,7 @@
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
+#include <errno.h>
|
|
|
|
#include "img.h"
|
|
|
|
@@ -117,30 +118,40 @@
|
|
int i;
|
|
if (type == unknown) {
|
|
I->err = IE_UNKNOWNTYPE;
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return 0;
|
|
} else if (!I->fp) {
|
|
I->err = IE_NOSTREAM;
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return 0;
|
|
- } else if (howmuch == none) return 1;
|
|
+ } else if (howmuch == none) {
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
+ return 1;
|
|
+ }
|
|
else for (i = 0; i < NUMFILEDRVS; ++i)
|
|
if (filedrvs[i].type == type) {
|
|
int r;
|
|
if (howmuch == header && filedrvs[i].loadhdr) {
|
|
r = filedrvs[i].loadhdr(I);
|
|
if (r) I->load = howmuch;
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return r;
|
|
} else if (filedrvs[i].loadimg) {
|
|
/* May have to load header first. */
|
|
- if (I->load != header && filedrvs[i].loadhdr && !filedrvs[i].loadhdr(I))
|
|
+ if (I->load != header && filedrvs[i].loadhdr && !filedrvs[i].loadhdr(I)) {
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return 0;
|
|
+ }
|
|
I->load = header;
|
|
r = filedrvs[i].loadimg(I);
|
|
if (r) I->load = full;
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return r;
|
|
}
|
|
}
|
|
|
|
I->err = IE_UNKNOWNTYPE;
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return 0;
|
|
}
|
|
|
|
@@ -160,6 +171,7 @@
|
|
I->fp = fopen(name, "rb");
|
|
if (!I->fp) {
|
|
I->err = IE_SYSERROR;
|
|
+ fprintf(stderr, "HF: fopen('%s') failed: %s\n", name, strerror(errno));
|
|
return 0;
|
|
}
|
|
|
|
@@ -172,13 +184,17 @@
|
|
char *q;
|
|
for (q = filedrvs[i].suffices; *q; q += strlen(q) + 1)
|
|
if (strcasecmp(p, q) == 0) {
|
|
+ int r;
|
|
I->type = filedrvs[i].type;
|
|
- return img_load(I, howmuch, I->type);
|
|
+ r = img_load(I, howmuch, I->type);
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
+ return r;
|
|
}
|
|
}
|
|
} else return img_load(I, howmuch, type);
|
|
|
|
I->err = IE_UNKNOWNTYPE;
|
|
+ if (feof(I->fp)) fclose(I->fp);
|
|
return 0;
|
|
}
|
|
|