On Thu, Jul 09, 2020 at 11:42:26PM +0400, Marc-André Lureau wrote: > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> > --- > block/ssh.c | 23 +++++++---------------- > 1 file changed, 7 insertions(+), 16 deletions(-) > > diff --git a/block/ssh.c b/block/ssh.c > index 098dbe03c15..c8f6ad79e3c 100644 > --- a/block/ssh.c > +++ b/block/ssh.c > @@ -180,9 +180,9 @@ static void sftp_error_trace(BDRVSSHState *s, const char > *op) > > static int parse_uri(const char *filename, QDict *options, Error **errp) > { > - URI *uri = NULL; > - QueryParams *qp; > - char *port_str; > + g_autoptr(URI) uri = NULL; > + g_autoptr(QueryParams) qp = NULL; > + g_autofree char *port_str = NULL; > int i; > > uri = uri_parse(filename); > @@ -192,23 +192,23 @@ static int parse_uri(const char *filename, QDict > *options, Error **errp) > > if (g_strcmp0(uri->scheme, "ssh") != 0) { > error_setg(errp, "URI scheme must be 'ssh'"); > - goto err; > + return -EINVAL; > } > > if (!uri->server || strcmp(uri->server, "") == 0) { > error_setg(errp, "missing hostname in URI"); > - goto err; > + return -EINVAL; > } > > if (!uri->path || strcmp(uri->path, "") == 0) { > error_setg(errp, "missing remote path in URI"); > - goto err; > + return -EINVAL; > } > > qp = query_params_parse(uri->query); > if (!qp) { > error_setg(errp, "could not parse query parameters"); > - goto err; > + return -EINVAL; > } > > if(uri->user && strcmp(uri->user, "") != 0) { > @@ -219,7 +219,6 @@ static int parse_uri(const char *filename, QDict > *options, Error **errp) > > port_str = g_strdup_printf("%d", uri->port ?: 22); > qdict_put_str(options, "server.port", port_str); > - g_free(port_str); > > qdict_put_str(options, "path", uri->path); > > @@ -232,15 +231,7 @@ static int parse_uri(const char *filename, QDict > *options, Error **errp) > } > } > > - query_params_free(qp); > - uri_free(uri); > return 0; > - > - err: > - if (uri) { > - uri_free(uri); > - } > - return -EINVAL; > } >
I had to look up the definition of g_autoptr, and it seems fine since there's a corresponding URI macro added in the first commit. ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org