Messages in this thread | | | Date | Tue, 10 Dec 2013 13:18:01 +0100 | From | Ingo Molnar <> | Subject | Re: [GIT PULL 00/21] perf/core improvements and fixes |
| |
* Adrian Hunter <adrian.hunter@intel.com> wrote:
> -void dso__set_short_name(struct dso *dso, const char *name) > +void dso__set_short_name(struct dso *dso, const char *name, bool sname_alloc) > { > if (name == NULL) > return; > + if (dso->sname_alloc) > + free((char *)dso->short_name); > + dso->sname_alloc = sname_alloc;
Calling the function option the same as the field name is asking for trouble - I'd suggest 'new_sname_alloc' for the parameter, or so.
And I'd also remove the 'const' from struct dso::short_name, it probably does not help code generation, because 'dso' is passed in as const in all the non-lifetime methods anyway.
That way the cast can be dropped from the free().
Similar problems exist with the usage of 'short_name' - it overloads the field name which makes it somewhat confusing, and it's also sometimes inconsistently named, such as 'name' in dso__set_short_name().
Ditto for 'long_name' handling.
Also, the 'sname_alloc' name sucks, it does not make it obvious that it's related to 'short_name', hiding its true significance (and hiding the broken life time handling of the flag/pointer combo). I'd rename it to something more descriptive, like ->short_name_allocated - or I'd rename everything to 'sname'/'lname' naming for short/long names.
Every time one runs into a crash like this it's a canary signal that cleanliness principles need hardening.
Thanks,
Ingo
| |