[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 05/13] block/ssh: auto-ify URI parsing variables
From: |
Richard W.M. Jones |
Subject: |
Re: [PATCH 05/13] block/ssh: auto-ify URI parsing variables |
Date: |
Thu, 23 Jul 2020 13:30:04 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Thu, Jul 09, 2020 at 11:42:26PM +0400, Marc-André Lureau wrote:
> Signed-off-by: Marc-André Lureau <marcandre.lureau@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
- [PATCH 00/13] RFC: use upcoming GUri for URI handling, Marc-André Lureau, 2020/07/09
- [PATCH 01/13] uri: add g_auto macros for URI & QueryParams, Marc-André Lureau, 2020/07/09
- [PATCH 02/13] block/nbd: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 03/13] block/vxhs: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 04/13] block/sheepdog: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 05/13] block/ssh: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- Re: [PATCH 05/13] block/ssh: auto-ify URI parsing variables,
Richard W.M. Jones <=
- [PATCH 06/13] block/nfs: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 07/13] block/gluster: auto-ify URI parsing variables, Marc-André Lureau, 2020/07/09
- [PATCH 08/13] build-sys: add HAVE_GLIB_GURI, Marc-André Lureau, 2020/07/09
- [PATCH 09/13] nbd: add GUri-based URI parsing version, Marc-André Lureau, 2020/07/09
- [PATCH 10/13] sheepdog: add GUri-based URI parsing, Marc-André Lureau, 2020/07/09
- [PATCH 11/13] nfs: add GUri-based URI parsing, Marc-André Lureau, 2020/07/09
- [PATCH 12/13] gluster: add GUri-based URI parsing, Marc-André Lureau, 2020/07/09
- [PATCH 13/13] ssh: add GUri-based URI parsing, Marc-André Lureau, 2020/07/09