Application crashes with enabled resource leaks report.

delphi package - automated exception handling
Post Reply
AlCaver
Posts: 7
Joined: Wed Jul 08, 2015 10:17 am

Application crashes with enabled resource leaks report.

Post by AlCaver »

Hello!

I use Borland C++ Builder 2010 and madExcept 4.0.13.
I develop windows service application which receives data from tcp/ip and process it.
When application allocates and deallocates lots of the memory blocks (several hundreds in second) during connections processing and in madExcept settings are enabled "report resource leaks" and "instantly crash on buffer overflow" application crashes after several minutes and in windows event log appears record:

Faulting application name: AutoGRAPHServer.exe, version: 5.2.14.603, time stamp: 0x00000000
Faulting module name: madExcept32.dll, version: 4.0.5.0, time stamp: 0x55f16f60
Exception code: 0xc0000005
Fault offset: 0x000cc946
Faulting process id: 0x1470
Faulting application start time: 0x01d1105bbfca0f65
Faulting application path: C:\AutoGRAPHServer4\AutoGRAPHServer.exe
Faulting module path: C:\AutoGRAPHServer4\madExcept32.dll
Report Id: 1043f0ac-8379-11e5-bf8a-00155d002801

When application works with lower load it works fine.

Is it possible to use "report resource leaks" and "instantly crash on buffer overflow" when application allocates/deallocates lots of the memory blocks?
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Application crashes with enabled resource leaks report.

Post by madshi »

Does the same thing happen if you disable "instantly crash"?

In theory madExcept should not care how often you allocate/release something. However, doing leak reporting and using the "instantly crash" feature both consumes additional RAM, so it's possible that you're running out of RAM. You can reduce the strain a bit by using only one of these features at a time.
AlCaver
Posts: 7
Joined: Wed Jul 08, 2015 10:17 am

Re: Application crashes with enabled resource leaks report.

Post by AlCaver »

Application doesn't crash when I disable "instantly crash".
I've tried to enable "instantly crash" only. Application crashed after 1 minute with the same exception. At that moment application allocated about 800 Mb of RAM.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Application crashes with enabled resource leaks report.

Post by madshi »

If it's not an "out of memory" exception, then this crash might actually be a buffer overrun, or something like that. Can you attach the full crash report here (zipped)?
AlCaver
Posts: 7
Joined: Wed Jul 08, 2015 10:17 am

Re: Application crashes with enabled resource leaks report.

Post by AlCaver »

madshi wrote:If it's not an "out of memory" exception, then this crash might actually be a buffer overrun, or something like that. Can you attach the full crash report here (zipped)?
I can't because crash report isn't created in this case.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Application crashes with enabled resource leaks report.

Post by madshi »

Oh ok, that's too bad. Unfortunately I don't have any good ideas right now. Although after thinking about it, 800MB of RAM means that there's an additional 800MB of RAM reserved, which cannot be used to make the whole "instantly crash" feature work. So my best guess is that really the process is running out of RAM. If that's the case, the "instantly crash" feature doesn't seem to be usable with your application atm, sadly.
AlCaver
Posts: 7
Joined: Wed Jul 08, 2015 10:17 am

Re: Application crashes with enabled resource leaks report.

Post by AlCaver »

I think about 700 Mb is used by madexcept. Because when "leak report" and "instantly crash" are disabled application doesn't allocate more than 100 Mb memory.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Application crashes with enabled resource leaks report.

Post by madshi »

Well, the problem is that madExcept consumes at least 2 memory pages for each allocation, when using "instantly crash". It's necessary to make the feature work. So if you have a lot of very small allocations, madExcept is quickly running out of memory pages. The number of active allocations is much more important than the added size of the allocated buffers. If you have one allocation with 100MB, that's no problem at all. If you have 100 million allocations with 1 byte each, there's no chance that could ever work, because madExcept would need to use 200 million memory pages for that.
AlCaver
Posts: 7
Joined: Wed Jul 08, 2015 10:17 am

Re: Application crashes with enabled resource leaks report.

Post by AlCaver »

madshi wrote:Well, the problem is that madExcept consumes at least 2 memory pages for each allocation, when using "instantly crash". It's necessary to make the feature work. So if you have a lot of very small allocations, madExcept is quickly running out of memory pages. The number of active allocations is much more important than the added size of the allocated buffers. If you have one allocation with 100MB, that's no problem at all. If you have 100 million allocations with 1 byte each, there's no chance that could ever work, because madExcept would need to use 200 million memory pages for that.
Thanks for explanation!
When my application crashes it allocates lots small buffers. So I think it's really out of memory.
rossmcm
Posts: 74
Joined: Thu Jun 09, 2005 2:05 am
Contact:

Re: Application crashes with enabled resource leaks report.

Post by rossmcm »

so by "for each allocation" you mean for each call to TWhatever.Create, right? Or each call to New/GetMem?

How big is a page ? 4096 bytes?

Do we still lose the memory even if we later destroy the object? If so, I can see big drawbacks in using things like TObjectList.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Application crashes with enabled resource leaks report.

Post by madshi »

Each Delphi memory manager allocation, regardless of which API is used. A page is 4096 bytes, IIRC. If you release an allocated object, you get the memory back, of course. And please note that this allocation behaviour only applies when using "instantly crash", it does *NOT* apply only when using leak reporting.
rossmcm
Posts: 74
Joined: Thu Jun 09, 2005 2:05 am
Contact:

Re: Application crashes with enabled resource leaks report.

Post by rossmcm »

Thanks Mathias. It's clear to me now ☺.

R
Post Reply