Skip to contentSkip to conversation

nfs-utils: Fix minor memory leaks before return.

PATCH In review Kenneth Dsouza 2 participants 2 messages Jun 20, 2018 – Jun 25, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs-utils: Fix minor memory leaks before return.

---
 support/junction/path.c            | 4 +++-
 support/nfsidmap/nfsidmap_common.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
support/junction/path.c +3 -1
index 68a1d13..e74e4c4 100644
@@ -326,8 +326,10 @@ nsdb_posix_to_path_array(const char *pathname, char ***path_array)
 			break;
 		next = strchrnul(component, '/');
 		length = (size_t)(next - component);
-		if (length > 255)
+		if (length > 255) {
+			nsdb_free_string_array(result);
 			return FEDFS_ERR_SVRFAULT;
+		}
 
 		result[i] = strndup(component, length);
 		if (result[i] == NULL) {
support/nfsidmap/nfsidmap_common.c +3 -1
index 5242c7e..f89b82e 100644
@@ -57,8 +57,10 @@ struct conf_list *get_local_realms(void)
 			return NULL;
 
 		node->field = calloc(1, NFS4_MAX_DOMAIN_LEN);
-		if (node->field == NULL)
+		if (node->field == NULL) {
+			free(node);
 			return NULL;
+		}
 
 		nfs4_get_default_domain(NULL, node->field, NFS4_MAX_DOMAIN_LEN);
 		toupper_str(node->field);
Signature · 1 line
2.14.3
#1 lore raw
Quoted 6 lines · Kenneth Dsouza
---
 support/junction/path.c            | 4 +++-
 support/nfsidmap/nfsidmap_common.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

Committed...

steved.

Quoted 34 lines
support/junction/path.c +3 -1
index 68a1d13..e74e4c4 100644
@@ -326,8 +326,10 @@ nsdb_posix_to_path_array(const char *pathname, char ***path_array)
 			break;
 		next = strchrnul(component, '/');
 		length = (size_t)(next - component);
-		if (length > 255)
+		if (length > 255) {
+			nsdb_free_string_array(result);
 			return FEDFS_ERR_SVRFAULT;
+		}
 
 		result[i] = strndup(component, length);
 		if (result[i] == NULL) {
support/nfsidmap/nfsidmap_common.c +3 -1
index 5242c7e..f89b82e 100644
@@ -57,8 +57,10 @@ struct conf_list *get_local_realms(void)
 			return NULL;
 
 		node->field = calloc(1, NFS4_MAX_DOMAIN_LEN);
-		if (node->field == NULL)
+		if (node->field == NULL) {
+			free(node);
 			return NULL;
+		}
 
 		nfs4_get_default_domain(NULL, node->field, NFS4_MAX_DOMAIN_LEN);
 		toupper_str(node->field);