forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SDK 4.01 memory free error

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Garak



Joined: 27 Jul 2005
Posts: 46

PostPosted: Mon Aug 01, 2005 2:15 pm    Post subject: SDK 4.01 memory free error Reply with quote

Hello,

I have identified an error in the SDK. Here is the series of events that yields the error:

1. Allocate memory in main thread via malloc.
2. Start a thread and pass in a pointer to the allocated memory.
3. Thread runs and uses allocated memory just fine.
4. Thread Deletes allocated memory via free (THREAD CRASHES)

When my thread attempts to delete the memory, it crashes. I have experimented and determined that the address of the memory allocated in main does not match the address of the memory passed into the created thread. I print the addess in both locations and they differ.

But... I know the memoy being used by my thread has somehow been initialized correctly. When I allocate the memory in main, I initilize it with ceratin values. When the thread accesses its copy of the memory, it has all the correct values. Only when I attempt to free this memory does my system crash.

I was using the origional PSP toolchain and SDK, and did not have this problem. The exact same code ran fine. Has anyone else seen this issue?
Back to top
View user's profile Send private message Send e-mail AIM Address
Garak



Joined: 27 Jul 2005
Posts: 46

PostPosted: Tue Aug 02, 2005 1:09 am    Post subject: Reply with quote

I should probably be a bit more specific when I say "THREAD CRASHES". What I really mean there is my PSP crashes and I have to turn it off/on to recover.
Back to top
View user's profile Send private message Send e-mail AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Tue Aug 02, 2005 4:06 am    Post subject: Reply with quote

Well install an exception handler using pspDebugInstallErrorHandler(NULL) in a kernel mode thread and you should get an error display when it crashes. If you need to know how to setup an exception handler look at the exception sample in pspsdk.

It could be dodgy free code but italso could be a stack overflow somewhere corrupting your pointer or any number of other things, the exception handler might at least point to what is going awry.
Back to top
View user's profile Send private message
Garak



Joined: 27 Jul 2005
Posts: 46

PostPosted: Tue Aug 02, 2005 4:39 am    Post subject: Reply with quote

The thread actually receives a pointer to an area of memory that has been initialized correctly. It's just the pointer in the thread points to an area of memory at a different address than what was created in the main thread.

It is as if a the area of memory in main was coppied and created within the thread's memory area. But.. calling free on the memory addess in the thread results in the PSP crashing. This is consistent with the behavior you get when you try to free memory that was not allocated via malloc/new.

I have a strong fealing the debug info would only tell me I am trying to free memory which was not allocated via maloc, which I allready know. In fact, I imagine the debug info won't even display, as the PSP is crashing when free is called, but I will give it a try and see what it shakes out.
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group