[Devel] memory allocation question
Norman Brandinger
norm at goes.com
Fri Nov 18 15:04:43 CET 2005
Hi Klaus,
A quick review of the code shows that the deallocation of cmd_line is
happening for all cases except where the allocation failed.
The confusion is probably caused by the use of "goto" statements. I am
against the use of "goto" in any programming if at all possible. They
ruin the entire idea of "structured programming". This topic has been
argued since the stone ages :)
In the case where no error condition exists, the line labeled error02
will still be executed and execution will continue to the line labeled
error01 (which then performs the deallocation). The only way to avoid
the deallocation is to "goto" error00 directly and this only happens if
the original memory allocation failed.
If I've missed something, I hope that someone will point it out.
Regards,
Norm
Klaus Darilion wrote:
> Hi!
>
> Probably this is a newbee question.
>
> I'm studying some source code and wonder about freeing allocated memory:
> file modules/exec/exec.c
>
> line 109: cmd_line=pkg_malloc(cmd_len);
>
> this is freed in line 189:
> pkg_free(cmd_line);
> but only if error01 happens.
>
> Shouldn't this be freed in all cases?
>
> regards
> klaus
>
> _______________________________________________
> Devel mailing list
> Devel at openser.org
> http://openser.org/cgi-bin/mailman/listinfo/devel
>
>
More information about the Devel
mailing list