[sr-dev] git:kamailio_3.0: modules/carrierroute: Prevent resource leak in case of error

Marius Zbihlei marius.zbihlei at 1and1.ro
Thu Aug 5 10:28:57 CEST 2010


Module: sip-router
Branch: kamailio_3.0
Commit: 821a4322a0902b827add7913705f72d5e50176b5
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=821a4322a0902b827add7913705f72d5e50176b5

Author: Marius Zbihlei <marius.zbihlei at 1and1.ro>
Committer: Marius Zbihlei <marius.zbihlei at 1and1.ro>
Date:   Thu Aug  5 11:02:14 2010 +0300

modules/carrierroute: Prevent resource leak in case of error

the 2 FILE* opened in file mode where not properly closed on all code paths

---

 modules/carrierroute/cr_config.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/modules/carrierroute/cr_config.c b/modules/carrierroute/cr_config.c
index 87969fa..1f0775a 100644
--- a/modules/carrierroute/cr_config.c
+++ b/modules/carrierroute/cr_config.c
@@ -157,18 +157,18 @@ static int backup_config(void) {
 		ch = fgetc(from);
 		if (ferror(from)) {
 			LM_ERR("Error reading source file.\n");
-			goto errout;
+			goto errclose;
 		}
 		if (!feof(from)) fputc(ch, to);
 		if (ferror(to)) {
 			LM_ERR("Error writing destination file.\n");
-			goto errout;
+			goto errclose;
 		}
 	}
 
 	if (fclose(from)==EOF) {
 		LM_ERR("Error closing source file.\n");
-		goto errout;
+		goto errclose;
 	}
 
 	if (fclose(to)==EOF) {
@@ -178,6 +178,10 @@ static int backup_config(void) {
 	LM_NOTICE("backup written to %s\n", backup_file);
 	pkg_free(backup_file);
 	return 0;
+errclose:
+	/* close the files so that resource leak is prevented ; ignore errors*/
+	fclose(from);
+	fclose(to);
 errout:
 	pkg_free(backup_file);
 	return -1;




More information about the sr-dev mailing list