C++ fopen memory leak

delphi package - automated exception handling

C++ fopen memory leak

Postby bwilt » Wed Oct 03, 2018 3:48 am

I've just grabbed the MaxEcept 4.0.20 for testing for a potential project using C++ language and RadStudio 10.2.2.

I have it running but have some library code that uses fopen quite a bit and get memory leaks from those functions.

Example code :-

Code: Select all
   char* filename = "w:\\test.txt";
   char* mode = "r";
   FILE* fd = fopen(filename, mode);
   if (fd != NULL) {
      fclose(fd);
   }


Indicates a memory leak at fclose(fd) ?

Also fstat line causes memory leak when that is added :-

Code: Select all
   char* filename = "w:\\test.txt";
   char* mode = "r";
   FILE* fd = fopen(filename, mode);
   if (fd != NULL) {
      struct stat statbuf;
      int handle = fileno(fd);
      fstat(handle, &statbuf);
      fclose(fd);
   }


Is there a way to figure out why or I guess potentially skipping leaks from fopen and fstat ?
bwilt
 
Posts: 8
Joined: Tue Oct 22, 2013 10:14 pm

Re: C++ fopen memory leak

Postby madshi » Tue Oct 16, 2018 1:38 pm

Sorry for the late reply.

I've just reproduced the issue (no problem) and done some digging. The first thing I checked was the leak report about the critical section reported in "__lock_stream". So I searched for that and found the function "_lock_stream" in the file "streams.c". After carefully analyzing the code, I came to the conclusion that it's a true leak in the C++ RTL. At this point I stopped my research. I don't really have the resources to go hunt for BCB RTL bugs, it's simply not my job.

To be honest, I sometimes regret having added leak reporting capability, because a pretty large percentage of my support work now consists of analyzing other people's code to find out why madExcept reports a leak there. In most cases it's a true leak, but still it's my time that is being lost on double checking if madExcept has a bug or not... :(

If in doubt, please assume that madExcept's leak report is correct.
madshi
Site Admin
 
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: No registered users and 5 guests

cron