Skip to content

Commit

Permalink
util/uri: do not check argument of uri_free()
Browse files Browse the repository at this point in the history
uri_free() checks if its argument is NULL in uri_clean() and g_free().
There is no need to check the argument before the call.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Message-Id: <20210629063602.4239-1-xypron.glpk@gmx.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
xypron authored and kevmw committed Jul 9, 2021
1 parent eb06cba commit c2615bd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
4 changes: 1 addition & 3 deletions block/nfs.c
Expand Up @@ -147,9 +147,7 @@ static int nfs_parse_uri(const char *filename, QDict *options, Error **errp)
if (qp) {
query_params_free(qp);
}
if (uri) {
uri_free(uri);
}
uri_free(uri);
return ret;
}

Expand Down
4 changes: 1 addition & 3 deletions block/ssh.c
Expand Up @@ -237,9 +237,7 @@ static int parse_uri(const char *filename, QDict *options, Error **errp)
return 0;

err:
if (uri) {
uri_free(uri);
}
uri_free(uri);
return -EINVAL;
}

Expand Down
22 changes: 6 additions & 16 deletions util/uri.c
Expand Up @@ -1340,7 +1340,7 @@ static void uri_clean(URI *uri)

/**
* uri_free:
* @uri: pointer to an URI
* @uri: pointer to an URI, NULL is ignored
*
* Free up the URI struct
*/
Expand Down Expand Up @@ -1939,15 +1939,9 @@ char *uri_resolve(const char *uri, const char *base)
val = uri_to_string(res);

done:
if (ref != NULL) {
uri_free(ref);
}
if (bas != NULL) {
uri_free(bas);
}
if (res != NULL) {
uri_free(res);
}
uri_free(ref);
uri_free(bas);
uri_free(res);
return val;
}

Expand Down Expand Up @@ -2190,12 +2184,8 @@ char *uri_resolve_relative(const char *uri, const char *base)
if (remove_path != 0) {
ref->path = NULL;
}
if (ref != NULL) {
uri_free(ref);
}
if (bas != NULL) {
uri_free(bas);
}
uri_free(ref);
uri_free(bas);

return val;
}
Expand Down

0 comments on commit c2615bd

Please sign in to comment.