diff mbox

[06/17] libnsdb: Fix memory leaks in nsdb_path_array_to_uri_pathname()

Message ID 20140511212856.13852.38227.stgit@seurat.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever May 11, 2014, 9:28 p.m. UTC
Ensure that "result" is properly freed before exiting with an error.

Fixes: 750fdf4bba4f5d4880ce7ad5b56451bd771cc3e2
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 src/libnsdb/path.c |   24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/src/libnsdb/path.c b/src/libnsdb/path.c
index f08560f..c58dc89 100644
--- a/src/libnsdb/path.c
+++ b/src/libnsdb/path.c
@@ -625,6 +625,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;
@@ -641,40 +642,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;
 }
 
 /**