Opened 12 years ago

Closed 12 years ago

#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: Blocking:
Patch: no


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:

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) {
    return 0;
  if (fstat(fd, &sb) < 0) {
    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


Change History (1)

comment:1 Changed 12 years ago by vadz

  • Resolution set to wontfix
  • Status changed from new to closed

We don't use this code, xmlwf contains the sources of a standalone tool which uses expat library and while it's distributed with it wxWidgets has nothing to do with it and I don't want to change any 3rd party sources without good reason to avoid introducing conflicts which will complicate upgrading them to the next version.

You should probably report this as a bug to expat/xmlwf maintainers (after checking that it's still present in the latest version).

Note: See TracTickets for help on using tickets.