1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
$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;
}
|