[PATCH weston 2/2] main: don't leak option strings
spitzak at gmail.com
Mon Sep 8 11:04:48 PDT 2014
Just to be clear, I have no objection to adding strdup() to all
functions that return strings.
I don't like adding unnecessary free() statements to the end of
called-once functions such as main, especially if you also have to add
labels and gotos and temporary variables to keep track of these.
On 09/08/2014 11:00 AM, Bill Spitzak wrote:
> On 09/07/2014 11:28 PM, Pekka Paalanen wrote:
>>> I think it is safe to assume the contents of argv will not get
>>> It is common to copy argv itself and modify that, but not to modify the
>>> strings it points at.
>> This would be feasible only if we can guarantee that no-one will ever
>> need to store a dynamically allocated string to any of the assigned
>> variables. If something produces a dynamically allocated string, then
>> you would need to track if you can free() the string or not.
> Or you can just leak that dynamically allocated value, which is what I
> would do.
> Trying to shut up valgrind on exit is an exercise in futility and adding
> a free() to try to shut it up often requires lots of unwanted code
> changes as this demonstrates.
> Any way it is not a big deal and any real system will probably be based
> on string objects of some sort. It sounds like you should also change
> the parse_options to copy all the string arguments too.
More information about the wayland-devel