Ticket #11194 (closed defect: wontfix)
resource leak in wxWidgets-2.9.0/src/expat/xmlwf/readfilemap.c
| Reported by: | ettl.martin | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 2.9.0 |
| Component: | GUI-all | Version: | 2.9.0 |
| Keywords: | resource leak | Cc: | |
| Blocked By: | Patch: | no | |
| Blocking: |
Description
Hi friends,
i have found a resource leak in file wxWidgets-2.9.0/src/expat/xmlwf/readfilemap.c at line 59. This means the file descriptor is not closed correctly.
Take a look at the source code:
int
filemap(const char *name,
void (*processor)(const void *, size_t, const char *, void *arg),
void *arg)
{
size_t nbytes;
int fd;
int n;
struct stat sb;
void *p;
fd = open(name, O_RDONLY|O_BINARY);
if (fd < 0) {
perror(name);
return 0;
}
if (fstat(fd, &sb) < 0) {
perror(name);
return 0;
}
if (!S_ISREG(sb.st_mode)) {
fprintf(stderr, "%s: not a regular file\n", name);
return 0;
}
nbytes = sb.st_size;
p = malloc(nbytes);
if (!p) {
fprintf(stderr, "%s: out of memory\n", name);
59 return 0;
}
....
}
this can easily fixed by adding an close(fd); before return 0;
This was found using the static code analysis tool cppcheck.
Best regards
Martin
Change History
Note: See
TracTickets for help on using
tickets.
