OpenQNX :: The QNX Community Portal

May 13, 2008 - 04:33 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 55 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
SHARIQUE
Post subject: Malloc Problem  PostPosted: Feb 08, 2006 - 07:15 AM
New Member


Joined: Aug 18, 2005
Posts: 3

I am facing problem regarding to malloc...
I am allocating char * type malloc(30)....it is not giving any error or warning on allocating time but when I am going to free it it gives memory fault error..
please tell me what is wrong there and solution

Programming Language- Watcom C
OS- QNX 4.25
Regs.
Santosh
 
 View user's profile Send private message  
Reply with quote Back to top
albrecht
Post subject:   PostPosted: Feb 08, 2006 - 09:17 AM
Senior Member


Joined: Mar 18, 2005
Posts: 136

Hello,

make sure you never write more than 30 bytes to your malloc()'ed buffer - depending on the actual layout of the heap, it may be possible to write more than 30 bytes without getting an error immediately, but when you free() the buffer, the heap manager's lists are corrupted, and only then the fault occurs. Try

Code:
char* buf;
buf = (char*)malloc(30);
/* No access to buf at all */
free(buf);


and see if that is working.

Regards,
Albrecht
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject:   PostPosted: Feb 08, 2006 - 12:28 PM
QNX Master


Joined: Sep 01, 2002
Posts: 2667

You are definitely doing something. One thing is for sure you should defnitely trust that malloc is working Wink

Post your code.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
maschoen
Post subject:   PostPosted: Feb 23, 2006 - 12:07 AM
QNX Master


Joined: Jun 25, 2003
Posts: 976

If the code posted is literal, that is there are no instructions at all between the malloc and the free, then you have previously corrupted your allocation chain. The fact that malloc functions anyway is irrelevant.
Try this code as a free standing program and see if it works. If so, then try commenting out suspicious code previous to the malloc to see if you can make the problem go away.
 
 View user's profile Send private message Send e-mail Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.