473,698 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Debugging memory leaks

Hello!
I made a short piece of code that I find very useful for debugging,
and I wanted to ask you if it is correct, somehow acceptable or if I
simply reinvented the wheel.
To deal with some bad bugs caused by memory leaks I ended up with this
simple solution: I made one header file that, when included, replaces
the malloc/calloc/realloc/free functions with some other functions
that do the actual job and insert (or remove) the pointers to the
allocated memory in a list. This way I can catch many errors as double
frees, allocations of zero size, or missing calls to free.
Obviously it works only when a given #define is set (NDEBUG, in my
case).
What do you think about it?
Thank you in advance!
(If you want to see the code I wrote a little page here:
http://technicalinsanity.org/out/simplegc/index.html)
Oct 14 '08
33 2876
On 16 Oct 2008 at 20:38, fm*****@gmail.c om wrote:
I was also wondering why the few times I asked something in clc (about
reentrant/thread-safe functions) everybody told me that it was not a
*standard c* related question, while this time quite everybody told me
to use *implementation defined* solutions. Funny!
Of course all these questions are perfectly on-topic in clc.

However, many people here are pursuing a political agenda - they want to
turn the group into a narrow discussion of ISO C, rather than all C. For
this reason, they will refuse to answer your questions, complain
vociferously, and quite possibly insult you into the bargain.

As they won't provide you with any help, the best thing to do is just to
ignore them.

Oct 16 '08 #21
fmas...@gmail.c om wrote:
Hello. Even if no one cares, I wanted to let the people who gave me
positive inputs know that I changed my code according to their good
suggestions.
I was also wondering why the few times I asked something in clc (about
reentrant/thread-safe functions) everybody told me that it was not a
*standard c* related question, while this time quite everybody told me
to use *implementation defined* solutions. Funny! Probably I should
swap my questions somehow, next time.
The only useful C answer to the thread-safe issue was to re-direct you
to forums more appropriate forum for such discussions, since the C
standard doesn't say anthing about threads.

The standard says a lot of things that are relevant to malloc()/
free(), and the feasibility of either wrapping them or replacing them.
Wrapping them is perfectly feasible, but replacing them necessarily
involves undefined behavior. Even explaining the fact that the
behavior is undefined, is more on-topic here than anything to do with
threads, because the C standard doesn't even explicitly say that the
behavior of threaded programs is undefined - the issue isn't discussed
at all.
Oct 16 '08 #22
fm*****@gmail.c om writes:
Hello. Even if no one cares, I wanted to let the people who gave me
positive inputs know that I changed my code according to their good
suggestions.
I was also wondering why the few times I asked something in clc (about
reentrant/thread-safe functions) everybody told me that it was not a
*standard c* related question, while this time quite everybody told me
to use *implementation defined* solutions. Funny! Probably I should
swap my questions somehow, next time.
Because there is a small clique of noisy regulars who want to limit. You
are with them or against the. See the Soduku thread as a great example
of regs purposely misunderstandin g basic scope issues to win points. All
of a sudden Bwian is allowed to not be specific and everyone understands
his unwritten meaning and in addition we have the meaning of extern
being redefined. You could not make it up.

Oct 16 '08 #23
On 16 Oct 2008 at 21:20, ja*********@ver izon.net wrote:
The only useful C answer to the thread-safe issue was to re-direct you
to forums more appropriate forum for such discussions, since the C
standard doesn't say anthing about threads.
The next version of the C++ standard will say a great deal about
threads.

If the C standard were to follow its lead, then by the "regulars"' own
criteria questions about threads would suddenly become "on topic" here,
which just goes to show how utterly nonsensical their position is.

Oct 16 '08 #24
dj******@csclub .uwaterloo.ca.i nvalid wrote:
>
.... snip ...
>
I have a bunch of malloc'ing code that I suspect has a memory-
management bug in it somewhere. Wouldn't it be nice if I could
just insert a #include at the top that pulls in some debugging
wrappers without having to change anything else in the code?
Try using DJGPP (see delorie.com) and installing nmalloc for it,
which has a comprehensive debugging package. See:

<http://cbfalconer.home .att.net/download/nmalloc.zip>

or you can try adapting the package to your system. The
non-standardisms are pretty common, but not all systems have a sbrk
call available.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Oct 17 '08 #25
Antoninus Twink <no****@nospam. invalidwrites:
On 16 Oct 2008 at 21:20, ja*********@ver izon.net wrote:
>The only useful C answer to the thread-safe issue was to re-direct you
to forums more appropriate forum for such discussions, since the C
standard doesn't say anthing about threads.

The next version of the C++ standard will say a great deal about
threads.

If the C standard were to follow its lead, then by the "regulars"' own
criteria questions about threads would suddenly become "on topic" here,
Yes.
which just goes to show how utterly nonsensical their position is.
No.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 17 '08 #26
Antoninus Twink wrote:
On 16 Oct 2008 at 21:20, ja*********@ver izon.net wrote:
>The only useful C answer to the thread-safe issue was to re-direct you
to forums more appropriate forum for such discussions, since the C
standard doesn't say anthing about threads.

The next version of the C++ standard will say a great deal about
threads.

If the C standard were to follow its lead, then by the "regulars"' own
criteria questions about threads would suddenly become "on topic" here,
Of course.
which just goes to show how utterly nonsensical their position is.
"nonsensica l" isn't the right spelling for "sensible", although I can
see how one could confuse them.

--
'It changed the future .. and it changed us.' /Babylon 5/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Oct 17 '08 #27
Chris Dollin said:
Antoninus Twink wrote:
>On 16 Oct 2008 at 21:20, ja*********@ver izon.net wrote:
>>The only useful C answer to the thread-safe issue was to re-direct you
to forums more appropriate forum for such discussions, since the C
standard doesn't say anthing about threads.

The next version of the C++ standard will say a great deal about
threads.

If the C standard were to follow its lead, then by the "regulars"' own
criteria questions about threads would suddenly become "on topic" here,

Of course.
Right.
>which just goes to show how utterly nonsensical their position is.

"nonsensica l" isn't the right spelling for "sensible", although I can
see how one could confuse them.
"When the facts change, I change my mind. What do you do, sir?" - John
Maynard Keynes.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 17 '08 #28
Chris Dollin wrote:
Antoninus Twink wrote:
>ja*********@ver izon.net wrote:
>>The only useful C answer to the thread-safe issue was to re-direct
you to forums more appropriate forum for such discussions, since
the C standard doesn't say anthing about threads.

The next version of the C++ standard will say a great deal about
threads.

If the C standard were to follow its lead, then by the "regulars"'
own criteria questions about threads would suddenly become "on
topic" here,

Of course.
>which just goes to show how utterly nonsensical their position is.

"nonsensica l" isn't the right spelling for "sensible", although I
can see how one could confuse them.
Which word does not apply to any such C language inclusion. There
is still no mention of threads in the proposed draft of the next
system, and even if it was present it should be shouted down. C
operates in a simple environment, especially in embedded systems,
and nothing that bars that should be proposed. Note that C++ is
very definitely not C.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Oct 17 '08 #29
CBFalconer wrote, On 17/10/08 15:16:
Chris Dollin wrote:
>Antoninus Twink wrote:
>>ja*********@ver izon.net wrote:

The only useful C answer to the thread-safe issue was to re-direct
you to forums more appropriate forum for such discussions, since
the C standard doesn't say anthing about threads.
The next version of the C++ standard will say a great deal about
threads.

If the C standard were to follow its lead, then by the "regulars"'
own criteria questions about threads would suddenly become "on
topic" here,
Of course.
>>which just goes to show how utterly nonsensical their position is.
"nonsensical " isn't the right spelling for "sensible", although I
can see how one could confuse them.

Which word does not apply to any such C language inclusion. There
is still no mention of threads in the proposed draft of the next
system, and even if it was present it should be shouted down. C
operates in a simple environment, especially in embedded systems,
and nothing that bars that should be proposed. Note that C++ is
very definitely not C.
I believe that there is talk of adding some threading support to the
next C standard and I don't see this as a problem for embedded systems.
The solution is simple and already in use, just as with the bulk of the
standard C library you make it only required for hosted implementations .
--
Flash Gordon
If spamming me sent it to sm**@spam.cause way.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Oct 17 '08 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
16686
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB (root@Pentium.suse.de) (gcc version 3.3 20030226 (prerelease) (SuSE Linux)) #1 Wed Aug 6 18:26:21 UTC 2003 Apache 1.3.27-41 PHP 4.3.1-52 MySQL 3.23.55-20
0
1866
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have used .Net memory profiler from Sci Tech to analyze the leaks and they are coming from inside HttpWebRequest and HttpRebResponse. When I run my code on VS2005, I do not get any leaks. Is this problem fixed in .Net 1.1 SP1? I may not be able to wait...
2
4953
by: Generic Usenet Account | last post by:
I have been using STL for a long time now, without any problems. Recently we generated a purification report on our software using Rational Purify, and we found some memory leaks. My colleague claims that some of the memory leaks are due to the fact that "STL is wrought with memory leaks". Of course I disagree. I think that there are no "inherent leaks" with STL, but if used improperly, leaks will occur. One common source of leak that...
5
4906
by: Aaron | last post by:
I just made a web app and there's some memory leak in the code. I can't use the VS.NET debugger for this. I would like to be able to see what's going on in the memory. What is the best memory debugging program? Aaron
41
3328
by: jacob navia | last post by:
In the C tutorial for lcc-win32, I have a small chapter about a debugging implementation of malloc. Here is the code, and the explanations that go with it. I would appreciate your feedback both about the code and the associated explanations. ---------------------------------------------------------------------
3
5321
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
6
1556
by: bob | last post by:
hi, I have a question I should know the answer to. I've delivered a working set of c++ libraries/dlls that have been fully tested and validated. Now my problem is that somebody else has been furiously fixing memory leaks and what not in another DLL that is used by my own. I suddenly find myself in the situation where MY dll's are now crashing out and I'm fairly sure, that the fixes in the other DLL have hosed my stuff. I'm thinking...
1
1583
by: mark Antony | last post by:
Hi... we are providing software support for one of the famous retailers in U.S. The code has been written in C++. Our field test customers feel that the application software is very slow. Before we deliver the software to our clients, we are in a urge to improve the performance of the application. Some of our software engineers suspect that the memory dirty pages are too high in the application. They feel that the code have lot of memory leaks....
16
5092
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have the ability to allocate different size chunks of memory not just a single size. It should error check for double free, etc. And it should be usable by a mixture of C and C++ subsystems. If I get that, I'm happy. Thank you very much.
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.