[fedfs-utils] [PATCH 09/17] libnsdb: Fix memory leaks in nsdb_path_array_to_uri_pathname()
Chuck Lever
chuck.lever at oracle.com
Tue May 27 08:37:39 PDT 2014
Ensure that "result" is properly freed before exiting with an error.
Fixes: 750fdf4bba4f5d4880ce7ad5b56451bd771cc3e2
Signed-off-by: Chuck Lever <chuck.lever at oracle.com>
---
src/libnsdb/path.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/libnsdb/path.c b/src/libnsdb/path.c
index ae9d5c64b6ad..6bfea3a01ea3 100644
--- a/src/libnsdb/path.c
+++ b/src/libnsdb/path.c
@@ -658,6 +658,7 @@ FedFsStatus
nsdb_path_array_to_uri_pathname(char * const *path_array, UriUriA *uri)
{
UriPathSegmentA *pos, *result;
+ FedFsStatus status;
size_t length, len;
char *component;
unsigned int i;
@@ -674,40 +675,49 @@ nsdb_path_array_to_uri_pathname(char * const *path_array, UriUriA *uri)
if (len == 0) {
xlog(D_GENERAL, "%s: Zero-length component", __func__);
- return FEDFS_ERR_BADNAME;
+ status = FEDFS_ERR_BADNAME;
+ goto out_err;
}
if (len > NAME_MAX) {
xlog(D_GENERAL, "%s: Component length too long", __func__);
- return FEDFS_ERR_NAMETOOLONG;
+ status = FEDFS_ERR_NAMETOOLONG;
+ goto out_err;
}
if (strchr(component, '/') != NULL) {
xlog(D_GENERAL, "%s: Local separator character "
"found in component", __func__);
- return FEDFS_ERR_BADNAME;
+ status = FEDFS_ERR_BADNAME;
+ goto out_err;
}
if (!nsdb_pathname_is_utf8(component)) {
xlog(D_GENERAL, "%s: Bad character in component",
__func__);
- return FEDFS_ERR_BADCHAR;
+ status = FEDFS_ERR_BADCHAR;
+ goto out_err;
}
length += STRLEN_SLASH + len;
if (length > PATH_MAX) {
xlog(D_GENERAL, "%s: Pathname too long", __func__);
- return FEDFS_ERR_NAMETOOLONG;
+ status = FEDFS_ERR_NAMETOOLONG;
+ goto out_err;
}
pos->next = nsdb_new_uri_path_segment(component);
if (pos->next == NULL) {
- nsdb_free_path_segments(result);
- return FEDFS_ERR_SVRFAULT;
+ status = FEDFS_ERR_SVRFAULT;
+ goto out_err;
}
pos = pos->next;
}
uri->pathHead = result;
return FEDFS_OK;
+
+out_err:
+ nsdb_free_path_segments(result);
+ return status;
}
/**
More information about the fedfs-utils-devel
mailing list