[alsa-devel] [PATCH 4/4 v6] ALSA: usb-audio: Scarlett mixer interface for 6i6, 18i6, 18i8 and 18i20
Takashi Iwai
tiwai at suse.de
Tue Nov 11 08:33:40 CET 2014
At Mon, 10 Nov 2014 16:00:17 -0600,
Chris J Arges wrote:
>
> <snip>
> > However...
> >
> >> + }
> >> +
> >> + /* assign to the appropriate control */
> >> + info->opt_master.names = (const char * const *)names;
> >> + info->opt_matrix.names = (const char * const *)names;
> >
> > ... I guess these will be leaked without destructor? This has to be
> > fixed. You need to add a flag indicating the need of kfree() and do
> > it in the own destructor accordingly.
> >
> >
> > thanks,
> >
> > Takashi
> >
> Where is the best place for this destructor?
>
> At the end of the snd_scarlett_controls_create function doesn't work due
> to opt_*.names being referenced by scarlett_ctl_enum_info afterwards.
>
> Creating a custom private_free callback doesn't seem correct either as I
> should only need to free the memory once and not repeatedly. However
> with a flag I could check and only free once on the callback.
Well, further looking at the code, it seems more buggy than I thought.
scarlett_create_strings_from_info() may override the existing pointer
that has been allocated. Again this leaks.
So, in the end, the cleanest way would be to generate a string in the
info callback itself. It doesn't need to allocate at all, it just
writes to uinfo->value.enumerated.name dynamically.
Takashi
More information about the Alsa-devel
mailing list