Problem occurs when using std C library in Symbian

Login to reply to this topic.
Tue, 2005-02-01 04:22
Joined: 2005-01-11
Forum posts: 7
Hi,

Could somebody explain to me why the environment reports memory
leaks during the debugging?  

__UHEAP_MARK;

FILE* aFile = fopen("c:\\system\\logs\\mylog.txt", "rb");  // aFile is not empty here
fclose( aFile );

__UHEAP_MARKEND;       // Panic this line

I put this into a very simple UI application and it reported memory leaks.
Why?Huh

Br
Martyn

Tue, 2005-02-01 04:26
Joined: 2005-01-11
Forum posts: 7
Problem occurs when using std C library in Symbian
Btw, I have included libc\stdio.h and put estlib.lib into my mmp file

Br
Martyn
Tue, 2005-02-01 05:05
Joined: 2004-02-05
Forum posts: 176
Problem occurs when using std C library in Symbian
Martyn,
The reason why you are experiencing a memory leak at this point is because there is memory being allocated that needs to be explicitly cleaned up when using the Symbian version of the C standard library.  Give this a tryÂ…

Code:
//include needed for CloseSTDLIB() call
#include <libc\sys\reent.h>
__UHEAP_MARK;

FILE* aFile = fopen("c:\\system\\logs\\mylog.txt", "rb"); // aFile is not empty here
fclose( aFile );

CloseSTDLIB();

__UHEAP_MARKEND; // Panic this line

Here is a quote from the SDK documentation that discusses this in more detail

Quote
Symbian OS has a requirement that all resources which were allocated by an application must be cleaned up by the time the program terminates. On the Emulator, in debug builds, failure to do this will cause a panic from the __UHEAP_MARKEND macro.

Because the data allocated in the thread-local storage for STDLIB's DLL (the _reent structure) is not automatically cleaned up when the environment is destroyed, it must be cleaned up by the user of STDLIB.

The function to achieve this is CloseSTDLIB(). To use this function, file epoc32\include\libc\sys\reent.h should be included in the project. Call CloseSTDLIB() after the point at which it is known that code in STDLIB's DLL will no longer be called and its thread-local storage no longer needed

Tue, 2005-02-01 05:30
Joined: 2005-01-11
Forum posts: 7
Problem occurs when using std C library in Symbian
It works! Thanks very much!

Br
Martyn
Thu, 2006-06-08 08:59
Joined: 2004-06-29
Forum posts: 109
Re: Problem occurs when using std C library in Symbian
Hi Darin,

i am trying to do exactly what you describe, but when compiling my project with CloseSTDLIB(); , the compiler says:
8<-------------------------------------
Errors caused tool to abort.

Link Error   : Undefined symbol: '_CloseSTDLIB'

Link Error   : referenced from 'CQP_DatatestAppUi::~CQP_DatatestAppUi(void) (??1CQP_DatatestAppUi@@UAE@XZ)' in QP_DATATESTAPPUI.cpp:259

Link Error   : Link failed

8<-------------------------------------

What did I miss?

Thanks, Marcel

Thu, 2006-06-08 14:29
Joined: 2005-08-08
Forum posts: 88
Re: Problem occurs when using std C library in Symbian
You forgot to add estlib.lib in your mmp file.
Mon, 2006-06-19 08:33
Joined: 2004-06-29
Forum posts: 109
Re: Problem occurs when using std C library in Symbian
Hi dragos_t

Of course!

Thanks for the hint.

Marcel
Wed, 2006-06-28 15:36
Joined: 2006-05-09
Forum posts: 114
Re: Problem occurs when using std C library in Symbian
i wouldnt recommend using standard C methods. there is always an equivalent specific to symbian.
Mon, 2006-11-20 19:41
Joined: 2005-08-20
Forum posts: 11
Re: Problem occurs when using std C library in Symbian
Great, I was just wondering what the heck was going on with memory leaks that didn't look like leaks at all! Smiley
  • Login to reply to this topic.