Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Detecting memory leaks using _CrtDumpMemoryLeaks

Reply
Thread Tools

Detecting memory leaks using _CrtDumpMemoryLeaks

 
 
lancer6238@yahoo.com
Guest
Posts: n/a
 
      04-04-2012
Hi,

This is my first time using the CRT library for detecting memory
leaks, and I'm using Visual C++ 2003. As mentioned in this website
(http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx), I included
the statements in my program

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

followed by another header file that contains all other header files
like stdio.h, windows.h and structure/function declarations. I also
have

_CrtDumpMemoryLeaks();

right before my function returns.

When I tried to build my program, I get the errors

error C2059: syntax error: 'constant'
error C2059: syntax error: 'string'
error C2733: second C linkage of overloaded function
'_aligned_malloc_dbg' not allowed

for the function prototypes in malloc.h, e.g.

_CRTIMP void * __cdecl calloc(size_t, size_t);
_CRTIMP void * __cdecl free(void *);

etc.

How do I run the memory check debugger correctly?

Thank you.

Regards,
Rayne
 
Reply With Quote
 
 
 
 
gwowen
Guest
Posts: n/a
 
      04-04-2012
On Apr 4, 3:28*am, "(E-Mail Removed)" <(E-Mail Removed)>
wrote:
> Hi,
>
> This is my first time using the CRT library for detecting memory
> leaks, and I'm using Visual C++ 2003. As mentioned in this website
> (http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx), I included
> the statements in my program
>
> #define _CRTDBG_MAP_ALLOC
> #include <stdlib.h>
> #include <crtdbg.h>
>
> followed by another header file that contains all other header files
> like stdio.h, windows.h and structure/function declarations. I also
> have


Move
#include <crtdbg.h>
to after the other #include <> statements (i.e. make sure its the last
one)
 
Reply With Quote
 
 
 
 
lancer6238@yahoo.com
Guest
Posts: n/a
 
      04-05-2012
On Apr 4, 6:47*am, gwowen <(E-Mail Removed)> wrote:
> On Apr 4, 3:28*am, "(E-Mail Removed)" <(E-Mail Removed)>
> wrote:
>
> > Hi,

>
> > This is my first time using the CRT library for detecting memory
> > leaks, and I'm using Visual C++ 2003. As mentioned in this website
> > (http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx), I included
> > the statements in my program

>
> > #define _CRTDBG_MAP_ALLOC
> > #include <stdlib.h>
> > #include <crtdbg.h>

>
> > followed by another header file that contains all other header files
> > like stdio.h, windows.h and structure/function declarations. I also
> > have

>
> Move
> #include <crtdbg.h>
> to after the other #include <> statements (i.e. make sure its the last
> one)


Thanks. I tried that, but now I have a different error:

error LNK2001: unresolved external symbol "int __cdecl
_CrtDumpMemoryLeaks(void)
error LNK2001: unresolved external symbol "__cdecl calloc_dbg(...)
error LNK2001: unresolved external symbol "__cdecl malloc_dbg(...)
error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
error LNK2001: unresolved external symbol "__cdecl operator_new(...)
....

I don't just have one source code file. My main function is in main.c,
and I'm trying to call CrtDumpMemoryLeaks() in FunctionA(), which is
in FunctionA.c. This FunctionA.c has

#include FunctionA.h

And this header file is #include'd in FunctionB.c. But FunctionB()
does not call CrtDumpMemoryLeaks().

So what I have in FunctionA.h is

#ifndef FUNCTIONA_H
#define FUNCTIONA_H

#define _CRTDBG_MAP_ALLOC

typedef unsigned __int8 uint8_t;
typedef unsigned char u_char;
typedef unsigned short u_short;

#include <WinSock2.h>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#incldue <pcap-int.h>
#include <string.h>
#include <strsafe.h>
#include <signal.h>
#include <time.h>

#include "FunctionC.h"
#include "FunctionD.h"

#include <crtdbg.h>

// Other #define
// Other extern variables
// Structure declarations
// Function declarations

#endif

I'm also trying to build this as a dll.
 
Reply With Quote
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      04-05-2012
http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
> On Apr 4, 6:47*am, gwowen <(E-Mail Removed)> wrote:
> > On Apr 4, 3:28*am, "(E-Mail Removed)" <(E-Mail Removed)>
> > wrote:
> >
> > > This is my first time using the CRT library for detecting memory
> > > leaks, and I'm using Visual C++ 2003. As mentioned in this website
> > > (http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx), I included
> > > the statements in my program

> >
> > > #define _CRTDBG_MAP_ALLOC
> > > #include <stdlib.h>
> > > #include <crtdbg.h>

> >
> > > followed by another header file that contains all other header files
> > > like stdio.h, windows.h and structure/function declarations. I also
> > > have

> >
> > Move
> > #include <crtdbg.h>
> > to after the other #include <> statements (i.e. make sure its the last
> > one)


> Thanks. I tried that, but now I have a different error:


> error LNK2001: unresolved external symbol "int __cdecl
> _CrtDumpMemoryLeaks(void)
> error LNK2001: unresolved external symbol "__cdecl calloc_dbg(...)
> error LNK2001: unresolved external symbol "__cdecl malloc_dbg(...)
> error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
> error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
> error LNK2001: unresolved external symbol "__cdecl operator_new(...)
> ...


And that aren't compiler errors anymore (so the code seems to
be fine now in the sense that the compiler has no trouble com-
piling it) but now you got linker errors. They tell you that
you rather likely aren't linking against the library that con-
tains the functions mentioned in the error messages. I have no
experience with this CrtDbg library but my guess is that it's
the one with all those missing symbols. So you probably forgot
to tell the linker that it is supposed to link your program
against it.
Regards, Jens
--
\ Jens Thoms Toerring ___ (E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
Geoff
Guest
Posts: n/a
 
      04-05-2012
On Wed, 4 Apr 2012 18:41:07 -0700 (PDT), "(E-Mail Removed)"
<(E-Mail Removed)> wrote:

>On Apr 4, 6:47*am, gwowen <(E-Mail Removed)> wrote:
>> On Apr 4, 3:28*am, "(E-Mail Removed)" <(E-Mail Removed)>
>> wrote:
>>
>> > Hi,

>>
>> > This is my first time using the CRT library for detecting memory
>> > leaks, and I'm using Visual C++ 2003. As mentioned in this website
>> > (http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx), I included
>> > the statements in my program

>>
>> > #define _CRTDBG_MAP_ALLOC
>> > #include <stdlib.h>
>> > #include <crtdbg.h>

>>
>> > followed by another header file that contains all other header files
>> > like stdio.h, windows.h and structure/function declarations. I also
>> > have

>>
>> Move
>> #include <crtdbg.h>
>> to after the other #include <> statements (i.e. make sure its the last
>> one)

>
>Thanks. I tried that, but now I have a different error:
>
>error LNK2001: unresolved external symbol "int __cdecl
>_CrtDumpMemoryLeaks(void)
>error LNK2001: unresolved external symbol "__cdecl calloc_dbg(...)
>error LNK2001: unresolved external symbol "__cdecl malloc_dbg(...)
>error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
>error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
>error LNK2001: unresolved external symbol "__cdecl operator_new(...)
>...
>
>I don't just have one source code file. My main function is in main.c,
>and I'm trying to call CrtDumpMemoryLeaks() in FunctionA(), which is
>in FunctionA.c. This FunctionA.c has
>
>#include FunctionA.h
>
>And this header file is #include'd in FunctionB.c. But FunctionB()
>does not call CrtDumpMemoryLeaks().
>
>So what I have in FunctionA.h is
>
>#ifndef FUNCTIONA_H
>#define FUNCTIONA_H
>
>#define _CRTDBG_MAP_ALLOC
>
>typedef unsigned __int8 uint8_t;
>typedef unsigned char u_char;
>typedef unsigned short u_short;
>
>#include <WinSock2.h>
>#include <windows.h>
>#include <stdlib.h>
>#include <stdio.h>
>#incldue <pcap-int.h>
>#include <string.h>
>#include <strsafe.h>
>#include <signal.h>
>#include <time.h>
>
>#include "FunctionC.h"
>#include "FunctionD.h"
>
>#include <crtdbg.h>
>
>// Other #define
>// Other extern variables
>// Structure declarations
>// Function declarations
>
>#endif
>
>I'm also trying to build this as a dll.


You must define _DEBUG in the preprocessor directives for the project.
You must link with the debug runtime. Set /MDd for the multithreaded
dynamic library (MSVCRTD.LIB).

You can access this option in the IDE via the Project Properties
dialog and the Code Generation | Runtime Library category. The default
for a DLL is /MDd since it's a VERY bad idea to statically link the
wrong version runtime.
 
Reply With Quote
 
lancer6238@yahoo.com
Guest
Posts: n/a
 
      04-09-2012
On Apr 6, 7:21*am, Geoff <(E-Mail Removed)> wrote:
> On Wed, 4 Apr 2012 18:41:07 -0700 (PDT), "(E-Mail Removed)"
>
>
>
>
>
>
>
>
>
> <(E-Mail Removed)> wrote:
> >On Apr 4, 6:47*am, gwowen <(E-Mail Removed)> wrote:
> >> On Apr 4, 3:28*am, "(E-Mail Removed)" <(E-Mail Removed)>
> >> wrote:

>
> >> > Hi,

>
> >> > This is my first time using the CRT library for detecting memory
> >> > leaks, and I'm using Visual C++ 2003. As mentioned in this website
> >> > (http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx), I included
> >> > the statements in my program

>
> >> > #define _CRTDBG_MAP_ALLOC
> >> > #include <stdlib.h>
> >> > #include <crtdbg.h>

>
> >> > followed by another header file that contains all other header files
> >> > like stdio.h, windows.h and structure/function declarations. I also
> >> > have

>
> >> Move
> >> #include <crtdbg.h>
> >> to after the other #include <> statements (i.e. make sure its the last
> >> one)

>
> >Thanks. I tried that, but now I have a different error:

>
> >error LNK2001: unresolved external symbol "int __cdecl
> >_CrtDumpMemoryLeaks(void)
> >error LNK2001: unresolved external symbol "__cdecl calloc_dbg(...)
> >error LNK2001: unresolved external symbol "__cdecl malloc_dbg(...)
> >error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
> >error LNK2001: unresolved external symbol "__cdecl realloc_dbg(...)
> >error LNK2001: unresolved external symbol "__cdecl operator_new(...)
> >...

>
> >I don't just have one source code file. My main function is in main.c,
> >and I'm trying to call CrtDumpMemoryLeaks() in FunctionA(), which is
> >in FunctionA.c. This FunctionA.c has

>
> >#include FunctionA.h

>
> >And this header file is #include'd in FunctionB.c. But FunctionB()
> >does not call CrtDumpMemoryLeaks().

>
> >So what I have in FunctionA.h is

>
> >#ifndef FUNCTIONA_H
> >#define FUNCTIONA_H

>
> >#define _CRTDBG_MAP_ALLOC

>
> >typedef unsigned __int8 uint8_t;
> >typedef unsigned char u_char;
> >typedef unsigned short u_short;

>
> >#include <WinSock2.h>
> >#include <windows.h>
> >#include <stdlib.h>
> >#include <stdio.h>
> >#incldue <pcap-int.h>
> >#include <string.h>
> >#include <strsafe.h>
> >#include <signal.h>
> >#include <time.h>

>
> >#include "FunctionC.h"
> >#include "FunctionD.h"

>
> >#include <crtdbg.h>

>
> >// Other #define
> >// Other extern variables
> >// Structure declarations
> >// Function declarations

>
> >#endif

>
> >I'm also trying to build this as a dll.

>
> You must define _DEBUG in the preprocessor directives for the project.
> You must link with the debug runtime. Set /MDd for the multithreaded
> dynamic library (MSVCRTD.LIB).
>
> You can access this option in the IDE via the Project Properties
> dialog and the Code Generation | Runtime Library category. The default
> for a DLL is /MDd since it's a VERY bad idea to statically link the
> wrong version runtime.


I do have _DEBUG in the preprocessor directives and /MDd for the Code
Generation | Runtime Library category.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting memory leaks on apache, mod_python Ilias Lazaridis Python 14 12-23-2007 09:25 AM
searching a function of standard libraries to help detecting memory leaks Diego Martins C++ 4 10-09-2006 05:46 PM
Detecting memory leaks Jive Python 2 11-21-2004 07:30 PM
ASP.NET - Detecting memory leaks ASP.Confused ASP .Net 2 07-16-2004 04:24 PM
detecting memory leaks in Perl Jerome Sui Perl Misc 0 07-13-2003 02:37 PM



Advertisments