LCDproc development and user support list

Text archives Help


[Lcdproc] [PATCH] MtxOrb.c for both 0.4.5 & 0.5


Chronological Thread 
  • From: reenoo AT gmx.de (Rene Wagner)
  • Subject: [Lcdproc] [PATCH] MtxOrb.c for both 0.4.5 & 0.5
  • Date: Wed Sep 29 13:08:02 2004

On Wed, 2004-09-15 at 21:19, Joris Robijn wrote:
> On 15 Sep 2004 at 20:06, Chris Lansley wrote:
>
> >
> > I'm fully aware of the comments in the configfile.h file - but this kind
> > of
> > interface is still asking for trouble, 1st because not everyone will look
> > at those comments, and 2nd (based on the code I've seen) not every one who
> > makes changes is a skilled programmer.
>
> Every scheme has its own trouble. At least this leaves the responsibility
> for cleaning up the string to the same file that allocated the string.
> That's a good principle.

Actually, I'm not quite sure about that. You can achieve more or less
the same by offering a config_string_free() function. That should be
more than obvious to most people and is in fact the standard way of
dealing with this (think of GLib's g_free() or more specialized
gtk_*_free() functions in GTK+).

> There have been enough trouble with programs that allocate space at place
> X and don't deallocate it, or do that twice (resulting in a deallocation
> of a different string that was much more recently allocated by an unknown
> function and accidently resided at the same memory location)

I don't think you solve anything this way. Having to copy memory in the
client code (as in code using a library/utility function) makes it
neccessary to free it there as well - allowing the same kind of
mistakes to be done in a different place only.

> Of course feeding a buffer and a maximum size to the config_* functions
> would have been safe too, but then you have a limitation in size and a
> less elegant function prototype.

I'd prefer to see the config_* functions to newly allocate memory on
each call and return a pointer to that. Corresponding config_*_free()
functions will make deallocation simple in the code using config_*
functions.

Rene





Archive powered by MHonArc 2.6.18.

Top of page