Re: Is correct ?
From: Christopher Benson-Manica (ataru_at_nospam.cyberspace.org)
Date: 02/21/05
- Next message: Christopher Benson-Manica: "Re: bitwise operators"
- Previous message: Michael Mair: "Re: using mktime()"
- In reply to: lasek: "Is correct ?"
- Next in thread: infobahn: "Re: Is correct ?"
- Reply: infobahn: "Re: Is correct ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Feb 2005 14:43:27 +0000 (UTC)
lasek <claudio.rossetti@acrm.it> spoke thus:
> char * testA(void)
> {
> char * acMsg=NULL;
> acMsg=malloc((14+1)*sizeof(char));
> strncpy(acMsg,"THIS IS A TEST,14);
> return acMsg;
> // free???
No, but...
> }
> strcpy(acMsg,testA());
...after strcpy() is called, you've lost the pointer that testA
returned, meaning that you no longer have the ability to free that
memory. You want something like
char *tmp=testA();
strcpy( acMsg, tmp ); /* assuming malloc() succeeded - you should check */
free( tmp );
Think about this in relation to infobahn's article :)
-- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
- Next message: Christopher Benson-Manica: "Re: bitwise operators"
- Previous message: Michael Mair: "Re: using mktime()"
- In reply to: lasek: "Is correct ?"
- Next in thread: infobahn: "Re: Is correct ?"
- Reply: infobahn: "Re: Is correct ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|