Re: Is correct ?

From: Christopher Benson-Manica (ataru_at_nospam.cyberspace.org)
Date: 02/21/05


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.


Relevant Pages

  • Re: Is correct ?
    ... you've lost the pointer that testA ... meaning that you no longer have the ability to free that ...
    (comp.lang.c)
  • Re: cdt glossary 0.1.1 (repost)
    ... and /or basic database research. ... A reference is a value used to refer ... ... "Known facts that can be recorded and have implicit meaning." ... variables of a pointer type - these variables ...
    (comp.databases.theory)
  • Re: cdt glossary 0.1.0
    ... And which might be aided by enforcing manipulation of the database by ... "Known facts that can be recorded and have implicit meaning." ... But by who, faction A, or faction B? ... Pointer - redirection vector ...
    (comp.databases.theory)
  • Re: The Bibles Poetry & Spiritualitys Value
    ... it's more like poetry than history or science, and, like poetry, its value lies in its ability to evoke meaning beyond the literal meaning of its words, concepts beyond their usual reach, between the lines. ... The Bible's universality, its ability to apply to a changing, evolving universe, is rooted in its interpretive nature. ... The Bible does not apply to a changing universe of values, only in the mind of liberal kooks that try to fashion their lifestyle to how *they* interpret the scriptures. ... What do the mathematical structures of a successful theory represent in the physical ontology? ...
    (talk.origins)
  • Re: Pointer equality and dereferencing
    ... Two values have the same hypervalue if they have exactly the same ... If we interpret "precise meaning" as any english people would, ... pointer values having the same value, ...
    (comp.std.c)