|
Posted by Vishuonline on December 15, 2005, 7:04 pm
Please log in for more thread options
Hi Folks,
I am facing a problem with CRT function call free() to dellocate memory I am
allocating by calloc call. My device is Orange SPV e200 Smartphone.
My free() call successfully deallocates the memory intermittently. i mean if
I run the application.. say 3 times. It deallocates 2 times.. at times.. only
1... And .. it gets better.. when it DOES NOT execute successfully.. its
CRASHES the APP.
I always check the pointer to be NOT NULL, before sending it to free() call.
Like
if(myPtr != NULL){free(myPtr);myPtr = NULL;}
I dont know how to address this issue. I am not able to do any on-device
debugging with this device,, for some strange reason. Whenever I launch the
app for on-device debugging.... the break point is never reached and the IDE
dies on me. Ok.. on-device debuggign.. problem apart.. I need some help on
the APP-CRASH on free() call.
Best,
|
|
Posted by Alex Feinman (MVP) on December 16, 2005, 2:51 am
Please log in for more thread options
Vishuonline wrote:
show/hide quoted text
> Hi Folks,
>
> I am facing a problem with CRT function call free() to dellocate memory I am
> allocating by calloc call. My device is Orange SPV e200 Smartphone.
> My free() call successfully deallocates the memory intermittently. i mean if
> I run the application.. say 3 times. It deallocates 2 times.. at times.. only
> 1... And .. it gets better.. when it DOES NOT execute successfully.. its
> CRASHES the APP.
> I always check the pointer to be NOT NULL, before sending it to free() call.
> Like
> if(myPtr != NULL){free(myPtr);myPtr = NULL;}
>
> I dont know how to address this issue. I am not able to do any on-device
> debugging with this device,, for some strange reason. Whenever I launch the
> app for on-device debugging.... the break point is never reached and the IDE
> dies on me. Ok.. on-device debuggign.. problem apart.. I need some help on
> the APP-CRASH on free() call.
>
> Best,
Check that the pointer you pass to free() is the same you got from
calloc(), i.e. it did not get overwritten
|
|
Posted by Vishuonline on December 16, 2005, 11:39 am
Please log in for more thread options Yes. I checked that one too.. All the pointers are unique place holders. And
there are on threads in the picture. Infact. I even check and display the
content inside the buffer, before calling free(),, it Still crashes... Any
clues??
Example code:
//////////////////////////////////////////////////////////
char * fName = (char *)calloc(strlen(colonTOKEN)-2,sizeof(char));
strcpy(fName,colonTOKEN+2);
TCHAR * fNameBuffer = (TCHAR *)calloc(strlen(fName),sizeof(TCHAR));
wsprintf(fNameBuffer,_T("%S"),fName);
TimedMessageBox(hwnd,fNameBuffer,_T("FULLNAME Debug Message"),MB_OK,1500);
show/hide quoted text
pContact->put_FirstName(fNameBuffer);//MAIN OPERATION
TimedMessageBox(hwnd,_T("ADDED"),_T("APPLICATION DEBUG"),MB_OK,1500);
//IT NEVER DISPLAYS THE "GOING TO NEXTTOKEN" MESSAGE BOX
if(fName != NULL && strlen(fName))
{
free(fName);//IT CRASHES HERE
fName = NULL;
}
if(fNameBuffer != NULL && wcslen(fNameBuffer))
{
free(fNameBuffer);
fNameBuffer = NULL;
}
TimedMessageBox(hwnd,_T("GOING TO NEXTTOKEN"),_T("APPLICATION
DEBUG"),MB_OK,1500);
//////////////////////////////////////////////////////////
Vishu
"Alex Feinman (MVP)" wrote:
show/hide quoted text
> Vishuonline wrote:
> > Hi Folks,
> >
> > I am facing a problem with CRT function call free() to dellocate memory I am
> > allocating by calloc call. My device is Orange SPV e200 Smartphone.
> > My free() call successfully deallocates the memory intermittently. i mean if
> > I run the application.. say 3 times. It deallocates 2 times.. at times..
only
show/hide quoted text
> > 1... And .. it gets better.. when it DOES NOT execute successfully.. its
> > CRASHES the APP.
> > I always check the pointer to be NOT NULL, before sending it to free() call.
> > Like
> > if(myPtr != NULL){free(myPtr);myPtr = NULL;}
> >
> > I dont know how to address this issue. I am not able to do any on-device
> > debugging with this device,, for some strange reason. Whenever I launch the
> > app for on-device debugging.... the break point is never reached and the IDE
> > dies on me. Ok.. on-device debuggign.. problem apart.. I need some help on
> > the APP-CRASH on free() call.
> >
> > Best,
>
> Check that the pointer you pass to free() is the same you got from
> calloc(), i.e. it did not get overwritten
>
|
|
Posted by Vishuonline on December 16, 2005, 12:44 pm
Please log in for more thread options Hmm.. I think I might have solved the issue.. I think the order of free()
calls is playing spoil sport.. This issue is related to fragmentation support
in heap memory..
I read that.. smartphone DOES support fragmentation.. which.. i believe
should allow free() calls.. irrespective of the order or calloc/malloc calls.
I dont know.. why the current behavior occurs.... but.. atleast.. its works
fine.. if i set the order right..
Thanks!
"Alex Feinman (MVP)" wrote:
show/hide quoted text
> Vishuonline wrote:
> > Hi Folks,
> >
> > I am facing a problem with CRT function call free() to dellocate memory I am
> > allocating by calloc call. My device is Orange SPV e200 Smartphone.
> > My free() call successfully deallocates the memory intermittently. i mean if
> > I run the application.. say 3 times. It deallocates 2 times.. at times..
only
show/hide quoted text
> > 1... And .. it gets better.. when it DOES NOT execute successfully.. its
> > CRASHES the APP.
> > I always check the pointer to be NOT NULL, before sending it to free() call.
> > Like
> > if(myPtr != NULL){free(myPtr);myPtr = NULL;}
> >
> > I dont know how to address this issue. I am not able to do any on-device
> > debugging with this device,, for some strange reason. Whenever I launch the
> > app for on-device debugging.... the break point is never reached and the IDE
> > dies on me. Ok.. on-device debuggign.. problem apart.. I need some help on
> > the APP-CRASH on free() call.
> >
> > Best,
>
> Check that the pointer you pass to free() is the same you got from
> calloc(), i.e. it did not get overwritten
>
|
|
Posted by Michael J. Salamone on December 17, 2005, 10:07 am
Please log in for more thread options The error is not in the CRT or fragmentation or order of frees.
The error is a heap corruption, calling free multiple times on the same
pointer, or some other bug which is putting the heap in a corrupt or
inconsistent state. The corruption occured *before* the call to free that
tanks.
You might sprinkle some calls to HeapValidate in your code to help narrow
down where the problem is.
If you want a tool that *might* help, check the link below.
--
Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com
show/hide quoted text
> Hmm.. I think I might have solved the issue.. I think the order of free()
> calls is playing spoil sport.. This issue is related to fragmentation
> support
> in heap memory..
> I read that.. smartphone DOES support fragmentation.. which.. i believe
> should allow free() calls.. irrespective of the order or calloc/malloc
> calls.
> I dont know.. why the current behavior occurs.... but.. atleast.. its
> works
> fine.. if i set the order right..
> Thanks!
> "Alex Feinman (MVP)" wrote:
>> Vishuonline wrote:
>> > Hi Folks,
>> > I am facing a problem with CRT function call free() to dellocate memory
>> > I am
>> > allocating by calloc call. My device is Orange SPV e200 Smartphone.
>> > My free() call successfully deallocates the memory intermittently. i
>> > mean if
>> > I run the application.. say 3 times. It deallocates 2 times.. at
>> > times.. only
>> > 1... And .. it gets better.. when it DOES NOT execute successfully..
>> > its
>> > CRASHES the APP.
>> > I always check the pointer to be NOT NULL, before sending it to free()
>> > call.
>> > Like
>> > if(myPtr != NULL){free(myPtr);myPtr = NULL;}
>> > I dont know how to address this issue. I am not able to do any
>> > on-device
>> > debugging with this device,, for some strange reason. Whenever I launch
>> > the
>> > app for on-device debugging.... the break point is never reached and
>> > the IDE
>> > dies on me. Ok.. on-device debuggign.. problem apart.. I need some help
>> > on
>> > the APP-CRASH on free() call.
>> > Best,
>> Check that the pointer you pass to free() is the same you got from
>> calloc(), i.e. it did not get overwritten
>>
|
| Similar Threads | Posted | | Free access to several paysites! Free movies - games - software - mp3 - and more! | January 17, 2006, 4:31 pm |
| Free Hot Phone Sex | January 21, 2006, 11:01 am |
| Free Hot Phone Sex | January 21, 2006, 11:01 am |
| SEX HOT LINE FREE TRIAL! | July 30, 2006, 8:27 am |
| Free WAV 2 MP3 encoder / PPC2003 / WM5 / WM6 | October 21, 2008, 12:59 am |
| on WM5, are malloc & free safe between different threads? | August 27, 2005, 6:38 pm |
| Web Hosting and Free Domain Name Registration | September 16, 2005, 2:33 pm |
| Re: Magic Indian Oil for MEN! Free Trial | August 11, 2006, 10:57 am |
| Re: Magic Indian Oil for MEN! Free Trial | August 11, 2006, 10:57 am |
| Re: Magic Indian Oil for MEN! Free Trial | August 11, 2006, 11:09 am |
|
>
> I am facing a problem with CRT function call free() to dellocate memory I am
> allocating by calloc call. My device is Orange SPV e200 Smartphone.
> My free() call successfully deallocates the memory intermittently. i mean if
> I run the application.. say 3 times. It deallocates 2 times.. at times.. only
> 1... And .. it gets better.. when it DOES NOT execute successfully.. its
> CRASHES the APP.
> I always check the pointer to be NOT NULL, before sending it to free() call.
> Like
> if(myPtr != NULL){free(myPtr);myPtr = NULL;}
>
> I dont know how to address this issue. I am not able to do any on-device
> debugging with this device,, for some strange reason. Whenever I launch the
> app for on-device debugging.... the break point is never reached and the IDE
> dies on me. Ok.. on-device debuggign.. problem apart.. I need some help on
> the APP-CRASH on free() call.
>
> Best,