[icinga-checkins] icinga.org: icinga-core/master: more s/malloc(size) + init/calloc(1, size)/ replacements (Andreas Ericsson)

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


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

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

more s/malloc(size) + init/calloc(1, size)/ replacements (Andreas Ericsson)

[--snip--]
This time in common/comments.c and common/downtime.c. Since we
really don't want to use explicit initialization on memory that
in all likelihood is already nul'ed out, as memory returned by
calloc() always is, and memory returned from malloc() that has
not been re-used by libc but comes straight from the kernel is,
this is a good thing.
[--snip--]

fixes #409

---

 Changelog         |    1 +
 common/comments.c |   10 +---------
 common/downtime.c |   14 +-------------
 3 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/Changelog b/Changelog
index 16776ab..4655567 100644
--- a/Changelog
+++ b/Changelog
@@ -37,6 +37,7 @@ FIXES
 * core: comments: Remove one comment at a time from hashlist (Hiren Patel)
 * core: fix checking of the open(2) system call (David Glick)
 * core: xodtemplate: Use macro magic to get rid of 900 LoC (Andreas Ericsson)
+* core: more s/malloc(size) + init/calloc(1, size)/ replacements (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/common/comments.c b/common/comments.c
index 14fafe4..4c51141 100644
--- a/common/comments.c
+++ b/common/comments.c
@@ -462,17 +462,9 @@ int add_comment(int comment_type, int entry_type, char *host_name, char *svc_des
 		return ERROR;
 
 	/* allocate memory for the comment */
-	if((new_comment=(comment *)malloc(sizeof(comment)))==NULL)
+	if((new_comment=(comment *)calloc(1, sizeof(comment)))==NULL)
 		return ERROR;
 
-	/* initialize vars */
-	new_comment->host_name=NULL;
-	new_comment->service_description=NULL;
-	new_comment->author=NULL;
-	new_comment->comment_data=NULL;
-	new_comment->next=NULL;
-	new_comment->nexthash=NULL;
-
 	/* duplicate vars */
 	if((new_comment->host_name=(char *)strdup(host_name))==NULL)
 		result=ERROR;
diff --git a/common/downtime.c b/common/downtime.c
index 672a689..c646bcd 100644
--- a/common/downtime.c
+++ b/common/downtime.c
@@ -883,15 +883,9 @@ int add_downtime(int downtime_type, char *host_name, char *svc_description, time
 		return ERROR;
 
 	/* allocate memory for the downtime */
-	if((new_downtime=(scheduled_downtime *)malloc(sizeof(scheduled_downtime)))==NULL)
+	if((new_downtime=(scheduled_downtime *)calloc(1, sizeof(scheduled_downtime)))==NULL)
 		return ERROR;
 
-	/* initialize vars */
-	new_downtime->host_name=NULL;
-	new_downtime->service_description=NULL;
-	new_downtime->author=NULL;
-	new_downtime->comment=NULL;
-
 	/* duplicate vars */
 	if((new_downtime->host_name=(char *)strdup(host_name))==NULL)
 		result=ERROR;
@@ -926,12 +920,6 @@ int add_downtime(int downtime_type, char *host_name, char *svc_description, time
 	new_downtime->triggered_by=triggered_by;
 	new_downtime->duration=duration;
 	new_downtime->downtime_id=downtime_id;
-#ifdef NSCORE
-	new_downtime->comment_id=0;
-	new_downtime->is_in_effect=FALSE;
-	new_downtime->start_flex_downtime=FALSE;
-	new_downtime->incremented_pending_downtime=FALSE;
-#endif
 
 	if(defer_downtime_sorting){
 		new_downtime->next=scheduled_downtime_list;





More information about the icinga-checkins mailing list