Module: sip-router Branch: master Commit: 2c034db7a3dc22886ad9b848d0c105a26f72e256 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2c034db7...
Author: Marius Zbihlei marius.zbihlei@1and1.ro Committer: Marius Zbihlei marius.zbihlei@1and1.ro Date: Thu Aug 5 11:08:17 2010 +0300
modules/carrierroute Fixed resource leak in case of error
2 FILE* where leaked(fclose was not called) in file mode on the error paths.
---
modules/carrierroute/cr_config.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/modules/carrierroute/cr_config.c b/modules/carrierroute/cr_config.c index 8b37fe6..92f96a9 100644 --- a/modules/carrierroute/cr_config.c +++ b/modules/carrierroute/cr_config.c @@ -157,17 +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"); + fclose(to); goto errout; }
@@ -178,6 +179,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;