Skip to contentSkip to conversation

nfs-server-generator: fix a potential memory leak issue

PATCH In review ChunYu Wang 2 participants 3 messages Apr 9, 2017 – Apr 10, 2017

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

PATCH 1/1 nfs-server-generator: fix a potential memory leak issue

---
Fix a potential memory leak issue caused by unfree pathname 'path'.

 systemd/nfs-server-generator.c | 1 +
 1 file changed, 1 insertion(+)
systemd/nfs-server-generator.c +1 -0
index 4aa6509..441cec5 100644
@@ -139,6 +139,7 @@ int main(int argc, char *argv[])
 	strcat(path, filebase);
 	f = fopen(path, "w");
 	if (!f)
+		free(path);
 		exit(1);
 	fprintf(f, "# Automatically generated by nfs-server-generator\n\n[Unit]\n");
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 12 lines · ChunYu Wang

---
Fix a potential memory leak issue caused by unfree pathname 'path'.

 systemd/nfs-server-generator.c | 1 +
 1 file changed, 1 insertion(+)
systemd/nfs-server-generator.c +0 -0
index 4aa6509..441cec5 100644

systemd/nfs-server-generator.c int main(int argc, char *argv[]) · line 143

Quoted 5 lines
systemd/nfs-server-generator.c +1 -0
@@ -139,6 +139,7 @@ int main(int argc, char *argv[])
 	strcat(path, filebase);
 	f = fopen(path, "w");
 	if (!f)
+		free(path);
 		exit(1);

First of all you need some '{' '}' so the process will not always exit when f != NULL...

Secondly dead process don't leak memory. :-) They don't leak anything... they are died! ;-)

steved.

Quoted 3 lines
systemd/nfs-server-generator.c +0 -0
 	fprintf(f, "# Automatically generated by nfs-server-generator\n\n[Unit]\n");
 
#2 lore raw

En, yes,

Thanks for reviewing and reminding, it is my fault [ : ( ].

Valgrind did not notice me about the syntax rationality, but it's my duty. Get down to learn, and thanks a lot.

Regards,
ChunYu Wang

Quoted 30 lines · Steve Dickson
Quoted 12 lines · ChunYu Wang

---
Fix a potential memory leak issue caused by unfree pathname 'path'.

 systemd/nfs-server-generator.c | 1 +
 1 file changed, 1 insertion(+)
systemd/nfs-server-generator.c +0 -0
index 4aa6509..441cec5 100644

systemd/nfs-server-generator.c int main(int argc, char *argv[]) · line 143

Quoted 5 lines
systemd/nfs-server-generator.c +1 -0
@@ -139,6 +139,7 @@ int main(int argc, char *argv[])
      strcat(path, filebase);
      f = fopen(path, "w");
      if (!f)
+             free(path);
              exit(1);

First of all you need some '{' '}' so the process will not always exit when f != NULL...

Secondly dead process don't leak memory. :-) They don't leak anything... they are died! ;-)

steved.

Quoted 3 lines
systemd/nfs-server-generator.c +0 -0
      fprintf(f, "# Automatically generated by nfs-server-generator\n\n[Unit]\n");