Hi,
I'm using LocalAlloc() in my application running Windows mobile 6.
When this is used in a Dialog class and another class member function is
called with an argument pointing the allocated memory, it meets 'data abort'
several steps after going into the callee class thesm.MaSMSdispatch().

what is this making this data abort?
Please let me know how I should use memory management between classes.
thanks you.

<here is the part of my codes.>
iService.sms_recipient.lpmsisdn=(TCHAR*)::LocalAlloc(GPTR,sizeof(lptemp)+1);
iService.sms_recipient.lpmsisdn[sizeof(lptemp)]=0;
_tcscpy(iService.sms_recipient.lpmsisdn,lptemp);

thesm.MaSMSdispatch( hDlg,(void *)&iService);

::LocalFree(iService.sms_recipient.lpmsisdn);

<error message>
Data Abort: Thread=82ec47b4 Proc=803e8410 'cmob01.exe'
AKY=00200001 PC=0002f630(cmob01.exe+0x0001f630)
RA=0002f3a4(cmob01.exe+0x0001f3a4) BVA=2c37009a FSR=00000001
The program '[c3221272] cmob01.exe' has exited with code 1067 (0x42b).

Re: Data abort when using LocalAlloc() between classes by Michael

Michael
Fri Mar 07 00:56:57 CST 2008

Usually heap corruption causes that. And that's what your problem is. You
are allocating sizeof(lptemp) but you really want tcslen(lptemp). sizeof()
will return 4 - the size of a pointer. You want the length of the string
that the pointer is pointing to, which is what tcslen will give you. Since
you only allocated 4, you're overrunning the buffer in the call to tcscpy
(assuming the string has length greater than 4).

--
Michael Salamone, eMVP
Entrek Software, Inc.
www.entrek.com


"sisimma" <sisimma@discussions.microsoft.com> wrote in message
news:2FE181FF-570E-49CD-9E3F-D925D734386E@microsoft.com...
> Hi,
> I'm using LocalAlloc() in my application running Windows mobile 6.
> When this is used in a Dialog class and another class member function is
> called with an argument pointing the allocated memory, it meets 'data
> abort'
> several steps after going into the callee class thesm.MaSMSdispatch().
>
> what is this making this data abort?
> Please let me know how I should use memory management between classes.
> thanks you.
>
> <here is the part of my codes.>
> iService.sms_recipient.lpmsisdn=(TCHAR*)::LocalAlloc(GPTR,sizeof(lptemp)+1);
> iService.sms_recipient.lpmsisdn[sizeof(lptemp)]=0;
> _tcscpy(iService.sms_recipient.lpmsisdn,lptemp);
>
> thesm.MaSMSdispatch( hDlg,(void *)&iService);
>
> ::LocalFree(iService.sms_recipient.lpmsisdn);
>
> <error message>
> Data Abort: Thread=82ec47b4 Proc=803e8410 'cmob01.exe'
> AKY=00200001 PC=0002f630(cmob01.exe+0x0001f630)
> RA=0002f3a4(cmob01.exe+0x0001f3a4) BVA=2c37009a FSR=00000001
> The program '[c3221272] cmob01.exe' has exited with code 1067 (0x42b).


Re: Data abort when using LocalAlloc() between classes by ctacke/>

ctacke/>
Thu Mar 06 09:18:46 CST 2008

Or even (tcslen(lptemp) * sizeof(TCHAR))


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com


"Michael Salamone" <mikesa#at#entrek#dot#com> wrote in message
news:F51D337F-0C02-4475-AD19-3F0DB4B255EF@microsoft.com...
> Usually heap corruption causes that. And that's what your problem is.
> You are allocating sizeof(lptemp) but you really want tcslen(lptemp).
> sizeof() will return 4 - the size of a pointer. You want the length of
> the string that the pointer is pointing to, which is what tcslen will give
> you. Since you only allocated 4, you're overrunning the buffer in the
> call to tcscpy (assuming the string has length greater than 4).
>
> --
> Michael Salamone, eMVP
> Entrek Software, Inc.
> www.entrek.com
>
>
> "sisimma" <sisimma@discussions.microsoft.com> wrote in message
> news:2FE181FF-570E-49CD-9E3F-D925D734386E@microsoft.com...
>> Hi,
>> I'm using LocalAlloc() in my application running Windows mobile 6.
>> When this is used in a Dialog class and another class member function is
>> called with an argument pointing the allocated memory, it meets 'data
>> abort'
>> several steps after going into the callee class thesm.MaSMSdispatch().
>>
>> what is this making this data abort?
>> Please let me know how I should use memory management between classes.
>> thanks you.
>>
>> <here is the part of my codes.>
>> iService.sms_recipient.lpmsisdn=(TCHAR*)::LocalAlloc(GPTR,sizeof(lptemp)+1);
>> iService.sms_recipient.lpmsisdn[sizeof(lptemp)]=0;
>> _tcscpy(iService.sms_recipient.lpmsisdn,lptemp);
>>
>> thesm.MaSMSdispatch( hDlg,(void *)&iService);
>>
>> ::LocalFree(iService.sms_recipient.lpmsisdn);
>>
>> <error message>
>> Data Abort: Thread=82ec47b4 Proc=803e8410 'cmob01.exe'
>> AKY=00200001 PC=0002f630(cmob01.exe+0x0001f630)
>> RA=0002f3a4(cmob01.exe+0x0001f3a4) BVA=2c37009a FSR=00000001
>> The program '[c3221272] cmob01.exe' has exited with code 1067 (0x42b).
>



Re: Data abort when using LocalAlloc() between classes by sisimma

sisimma
Fri Mar 07 14:21:00 CST 2008

Thanks all.
that's what I found yesterday too.

It should have been (tcslen(lptemp) * sizeof(TCHAR))

Have a good day every moment

"<ctacke/>" wrote:

> Or even (tcslen(lptemp) * sizeof(TCHAR))
>
>
> --
>
> Chris Tacke, eMVP
> Join the Embedded Developer Community
> http://community.opennetcf.com
>
>
> "Michael Salamone" <mikesa#at#entrek#dot#com> wrote in message
> news:F51D337F-0C02-4475-AD19-3F0DB4B255EF@microsoft.com...
> > Usually heap corruption causes that. And that's what your problem is.
> > You are allocating sizeof(lptemp) but you really want tcslen(lptemp).
> > sizeof() will return 4 - the size of a pointer. You want the length of
> > the string that the pointer is pointing to, which is what tcslen will give
> > you. Since you only allocated 4, you're overrunning the buffer in the
> > call to tcscpy (assuming the string has length greater than 4).
> >
> > --
> > Michael Salamone, eMVP
> > Entrek Software, Inc.
> > www.entrek.com
> >
> >
> > "sisimma" <sisimma@discussions.microsoft.com> wrote in message
> > news:2FE181FF-570E-49CD-9E3F-D925D734386E@microsoft.com...
> >> Hi,
> >> I'm using LocalAlloc() in my application running Windows mobile 6.
> >> When this is used in a Dialog class and another class member function is
> >> called with an argument pointing the allocated memory, it meets 'data
> >> abort'
> >> several steps after going into the callee class thesm.MaSMSdispatch().
> >>
> >> what is this making this data abort?
> >> Please let me know how I should use memory management between classes.
> >> thanks you.
> >>
> >> <here is the part of my codes.>
> >> iService.sms_recipient.lpmsisdn=(TCHAR*)::LocalAlloc(GPTR,sizeof(lptemp)+1);
> >> iService.sms_recipient.lpmsisdn[sizeof(lptemp)]=0;
> >> _tcscpy(iService.sms_recipient.lpmsisdn,lptemp);
> >>
> >> thesm.MaSMSdispatch( hDlg,(void *)&iService);
> >>
> >> ::LocalFree(iService.sms_recipient.lpmsisdn);
> >>
> >> <error message>
> >> Data Abort: Thread=82ec47b4 Proc=803e8410 'cmob01.exe'
> >> AKY=00200001 PC=0002f630(cmob01.exe+0x0001f630)
> >> RA=0002f3a4(cmob01.exe+0x0001f3a4) BVA=2c37009a FSR=00000001
> >> The program '[c3221272] cmob01.exe' has exited with code 1067 (0x42b).
> >
>
>
>

Re: Data abort when using LocalAlloc() between classes by Scott

Scott
Fri Mar 07 14:57:19 CST 2008

"<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:
>Or even (tcslen(lptemp) * sizeof(TCHAR))

Or even ((tcslen(lptemp) + 1) * sizeof(TCHAR))

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
There are no American infidels in Baghdad. Never!
-- Mohammed Saeed al-Sahhaf, Iraqi Information Minister

Re: Data abort when using LocalAlloc() between classes by ctacke/>

ctacke/>
Fri Mar 07 16:13:17 CST 2008

Sure - you and your attempts to prevent buffer overruns....

-Chris

"Scott Seligman" <seligman@example.com> wrote in message
news:fqsa7f$o20$1@panix3.panix.com...
> "<ctacke/>" <ctacke[at]opennetcf[dot]com> wrote:
>>Or even (tcslen(lptemp) * sizeof(TCHAR))
>
> Or even ((tcslen(lptemp) + 1) * sizeof(TCHAR))
>
> --
> --------- Scott Seligman <scott at <firstname> and michelle dot
> net> ---------
> There are no American infidels in Baghdad. Never!
> -- Mohammed Saeed al-Sahhaf, Iraqi Information Minister