Skip to contentSkip to conversation

Fix small memory leak

PATCH Applied Thomas Jarosch 2 participants 2 messages Oct 2, 2011 MD RAID

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix small memory leak

Credit goes to cppcheck.

---
 policy.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
policy.c +4 -1
index 2bbbac8..4a6ef82 100644
@@ -757,8 +757,10 @@ int policy_check_path(struct mdinfo *disk, struct map_ent *array)
 
 	snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path);
 	f = fopen(path, "r");
-	if (!f)
+	if (!f) {
+		free(id_path);
 		return 0;
+	}
 
 	rv = fscanf(f, " %s %x:%x:%x:%x\n",
 		    array->metadata,
@@ -767,6 +769,7 @@ int policy_check_path(struct mdinfo *disk, struct map_ent *array)
 		    array->uuid+2,
 		    array->uuid+3);
 	fclose(f);
+	free(id_path);
 	return rv == 5;
 }
 
Signature · 1 line
1.7.4.4
Applied
#1 lore raw
Quoted 24 lines · On Sun, 02 Oct 2011 21:45:41 +0200 Thomas Jarosch…

Credit goes to cppcheck.

---
 policy.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
policy.c +3 -1
index 2bbbac8..4a6ef82 100644
@@ -757,8 +757,10 @@ int policy_check_path(struct mdinfo *disk, struct map_ent *array)
 
 	snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path);
 	f = fopen(path, "r");
-	if (!f)
+	if (!f) {
+		free(id_path);
 		return 0;
+	}
 
 	rv = fscanf(f, " %s %x:%x:%x:%x\n",
 		    array->metadata,

policy.c int policy_check_path(struct mdinfo *disk, struct map_ent *array) · line 775

Quoted 7 lines
policy.c +1 -0
@@ -767,6 +769,7 @@ int policy_check_path(struct mdinfo *disk, struct map_ent *array)
 		    array->uuid+2,
 		    array->uuid+3);
 	fclose(f);
+	free(id_path);
 	return rv == 5;
 }
 

applied. Thanks.

NeilBrown