[icinga-checkins] icinga.org: icinga-core/master: base/commands.c: Fix error path of opening checkresult files (Andreas Ericsson)

git at icinga.org git at icinga.org
Wed May 19 13:41:53 CEST 2010


Module: icinga-core
Branch: master
Commit: 436324b3120858ae582219e6139f9de90d342aa0
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=436324b3120858ae582219e6139f9de90d342aa0

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Wed May 12 22:45:43 2010 +0200

base/commands.c: Fix error path of opening checkresult files (Andreas Ericsson)

[--snip--]
Previously we used to check that the returned filedescriptor
was larger than 0 to consider it a success and silently return
if it wasn't, but open() (as all other system calls) can return
0 on a successful invocation. Previously, this resulted in one
lost filedescriptor and the memory used for storing the path
to the checkresult file being leaked.

This patch takes care of both those leaks.
[--snip--]

patch is fine, removed one of those nifty printf hexcode
eastereggs too (as it's useless code).

fixes #423

---

 Changelog       |    1 +
 base/commands.c |   12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/Changelog b/Changelog
index 88849ec..10147dd 100644
--- a/Changelog
+++ b/Changelog
@@ -41,6 +41,7 @@ FIXES
 * core: common/objects.c: Remove unused functions (Andreas Ericsson)
 * core: header files: Remove dead prototypes (Andreas Ericsson)
 * core: remove grab_contactgroup_macros() and its prototype (Andreas Ericsson)
+* core: base/commands.c: Fix error path of opening checkresult files (Andreas Ericsson)
 
 * idoutils: Host DB inserts use string 'NULL\n' instead of NULL (William Preston)
 * idoutils: ndo2db_get_object_id fails to return existing IDs (William Preston)
diff --git a/base/commands.c b/base/commands.c
index 3749ea9..e0160b5 100644
--- a/base/commands.c
+++ b/base/commands.c
@@ -4965,15 +4965,17 @@ void process_passive_checks(void){
 
 	/* open a temp file for storing check result(s) */
 	old_umask=umask(new_umask);
-	asprintf(&checkresult_file,"\x67\141\x65\040\x64\145\x6b\162\157\167\040\145\162\145\150");
-	my_free(checkresult_file);
 	asprintf(&checkresult_file,"%s/checkXXXXXX",temp_path);
 	checkresult_file_fd=mkstemp(checkresult_file);
 	umask(old_umask);
-	if(checkresult_file_fd>0)
-		checkresult_file_fp=fdopen(checkresult_file_fd,"w");
-	else
+
+	if(checkresult_file_fd < 0) {
+		logit(NSLOG_RUNTIME_ERROR,TRUE,"Failed to open checkresult file '%s': %s\n", checkresult_file, strerror(errno));
+		free(checkresult_file);
 		return;
+	}
+
+	checkresult_file_fp=fdopen(checkresult_file_fd,"w");
 	
 	time(&current_time);
 	fprintf(checkresult_file_fp,"### Passive Check Result File ###\n");





More information about the icinga-checkins mailing list