Memory Leak and USER 42

Login to reply to this topic.
Fri, 2005-07-08 10:16
Joined: 2004-10-01
Forum posts: 35
Hello All,
I have 2 questions.

1. Symbian supports fopen and fclose functions. But when i execute the following code, It gives an alloc panic i.e momory leak.

        User::__DbgMarkStart(0);
        FILE* fp = fopen("C:\\Temp.bin","wb+");
        TInt ret = fclose(fp);
         RDebug::Printf("\nfclose Returned %d",ret);
        User::__DbgMarkEnd(0,0);

       DbgMarkStart/DbgMarkEnd  have been used to check the memory leak. fclose function is returning 0 (Successfully closed 
       the file). I am not getting why this memory leak is happening.

       Alternatively, I know i can use RFs and RFile Classes to do file related operations, but the point is that if symbian supports fopen 
       and fclose there should not be any memory leak.

      Any Suggestions???

2. I have an application. It runs and closes fine without any panic. But when i try to reopen the same application, It gives me USER 42
    panic. I am not getting any clue to this. What could be the reason? Has anybody faced this kind of error earlier?



Please Help me in this regard.
Thanks in Advance
Pinky


Fri, 2005-07-08 10:26
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: Memory Leak and USER 42
USER 42 - from SDK documentation.

This panic is raised by a number of RHeap member functions, AllocLen(), Free(), FreeZ(), ReAlloc(), ReAllocL(), Adjust() and AdjustL() when a pointer passed to these functions does not point to a valid cell.

Fri, 2005-07-08 10:43
Joined: 2004-01-09
Forum posts: 188
Re: Memory Leak and USER 42
The Symbian platform 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.


----
Chetan Kulshrestha

Fri, 2005-07-08 10:50
Joined: 2004-07-12
Forum posts: 90
Re: Memory Leak and USER 42
Shouldn't you delete fp?

For quality Symbian idling, join #symbian at irc.freenode.net

Fri, 2005-07-08 11:09
Joined: 2004-10-01
Forum posts: 35
Re: Memory Leak and USER 42
Chetan:
      I Tried using CloseSTDLIB() but to no avail. I am still getting the USER 42 while reopening.
savaa2:
      There is no need to delete fp. fopen/fclose work like this only. And if u try deleting the fp, u will get a KERN-EXEC 3 panic,   
      which means a bad instruction in the sense that u r deleting a allready deleted thing.
Fri, 2005-07-08 11:18
Joined: 2004-07-12
Forum posts: 90
Re: Memory Leak and USER 42
okay.

For quality Symbian idling, join #symbian at irc.freenode.net

Fri, 2005-07-08 11:20
Joined: 2004-01-09
Forum posts: 188
Re: Memory Leak and USER 42
That solution is for Alloc panic u r getting..

for USER 42, there might be something where u r refering a memory loaction which is not allocated. But it is strange that only reopening is givin u that panic.. Have you tried with rebuilding the whole application.
and remember to call CloseSTDLIB() at the end ( while exiting the application ) if u r using the C STDLIB functions.

savaa2: u should not delete fp. As it stores the reference to the file while we call fopen, but as soon as we call fclose, the reference gets delete.

----
Chetan Kulshrestha

Fri, 2005-07-08 12:58
Joined: 2004-10-01
Forum posts: 35
Re: Memory Leak and USER 42
Thx Very Much Chetan.
I am not getting the Alloc Panic now. But I shud say its a kind of work around. This problem shud not come at the first place itself.
If Symbian supports fopen/fclose then there shud be no memory leak of such kind.
Anyway, i learned a useful thing today..Thx very much.

Regarding the Reopening error, Yes i am rebuilding the whole application but to no avail. Actually there arei 2 things i am doing with the application.

1. Just open the application ..close it...Now, there will be no error while reopening.

2. Open the application....do sth (like, i am accessing camera for preview)...release the resources of camera...close the application....Now if i try to re-open, USER 42 comes. So probably I have missed sth while releasing the resources accquired by camera, but in this case it shud panic while closing the application for the first time but it does not panic at all..I am not getting any clue to this...

Any Suggestions???


Thx
~Pinky
Fri, 2005-07-08 13:15
Joined: 2004-01-09
Forum posts: 188
Re: Memory Leak and USER 42
In ur application are you trying to access some other application which is continuously running in background..

So while connecting to that server, may be at first time u r not getting any panic, but next time when u try to connect it, it throw a panic as the previous connection is still exist from same client.

But u r right as it should give panic while exiting the application.
one more thing that this panic is not related with releasing the resource, you r passing a reference of a not allocated memory location. It is very difficult to ssy anything without looking in code.

Anyway, are u facing the problem on emulator or device? Try it on device first because...u should not believe on emulator everytime.
if this does not resolve the problem than u can debug the crash point, where actually it is crashing.

----
Chetan Kulshrestha

Fri, 2005-07-08 13:22
Joined: 2004-10-01
Forum posts: 35
Re: Memory Leak and USER 42
No i am not trying to access or connect to some other application.
I am testing this application on the device.

How can i debug the crash point??

Thx
~Pinky
Fri, 2005-07-08 13:27
Joined: 2004-01-09
Forum posts: 188
Re: Memory Leak and USER 42

U can put log statements, write those statements in the file. When panic occur... see the last statement in the log file..
It may be bit lenghty but there is no other way to debug on device as I know.

----
Chetan Kulshrestha

Tue, 2006-01-10 10:25
Joined: 2005-06-11
Forum posts: 85
Re: Memory Leak and USER 42
pinky............have u solved the User 42 error.....I m also facing this error.............could anyone help?

Wise People talk because they have something to say . Fools talk because thay have to say somthing.

Wed, 2006-01-11 13:18
Joined: 2004-11-29
Forum posts: 1134
Re: Memory Leak and USER 42
USER 42 commonly occours if you are:

1. trying to delete an object that is already deleted. (if two classes share a pointer, make sure only one of them is the "owner" responsible for deleting it)

2. writeing outside the bounds of an array or similar, corrupting a pointer allocated next to it, that you then try to free. (for example an array as a member variable)

3. writeing outside the bounds of an array or similar, that is allocated on the heap, corrupting the heap cell after the array, causing USER 42 when trying to delete that cell...

Try look for those kinds of errors.
Tue, 2008-04-22 07:52
Joined: 2007-09-26
Forum posts: 1
Re: Memory Leak and USER 42

I am also facing the same problem, Panic code USER 42. Application is running fine, but when I try to close the application it gives this error message. Can anyone please help me in this?..Please.

Tue, 2008-04-22 08:00
Joined: 2003-12-05
Forum posts: 586
Re: Memory Leak and USER 42

I am also facing the same problem, Panic code USER 42. Application is running fine, but when I try to close the application it gives this error message. Can anyone please help me in this?..Please.

There's lots of help already in the above discussion. What more do you want? Especially when you provide no code or context to you problem at all?!

  • Login to reply to this topic.