On 2/10/20 3:10 PM, Richard W.M. Jones wrote:
On Mon, Feb 10, 2020 at 01:44:14PM -0600, Eric Blake wrote:
> A comment in the code mentioned something that didn't actually work,
> but which can be useful for user-directed logging of what other
> callbacks they might want to implement.
>
> Signed-off-by: Eric Blake <eblake(a)redhat.com>
> ---
>
> I haven't pushed this one, becuase I'm not sure if we want it; but it
> was easy enough to whip together after an IRC question earlier today.
>
> @@ -255,11 +261,15 @@ static int
> add_method (const char *key, const char *value)
> {
> char *script;
> + char *tmp = missing; /* Needed to allow user override of missing */
>
> - if (get_script (key) != missing) {
> + missing = NULL;
> + if (get_script (key) != NULL) {
> + missing = tmp;
> nbdkit_error ("method %s defined more than once on the command line",
key);
> return -1;
> }
> + missing = tmp;
This leaks the missing global?
Surprisingly not. We end up storing two malloc'd strings pointing to
the same script name, one in 'missing' (which gets freed independently),
and one in 'method_scripts[index_of_missing]' (which gets freed in our
pass over method_scripts). But yes, I'll make sure to double-check a
valgrind run before committing.
But yes the idea is fine, so ACK.
Rich.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org