Code

Fix the memory allocation for the thresholds data
authorHolger Weiss <holger@zedat.fu-berlin.de>
Mon, 1 Jun 2009 23:11:19 +0000 (01:11 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Mon, 1 Jun 2009 23:11:19 +0000 (01:11 +0200)
Allocate the appropriate amount of memory for storing the thresholds
data.  Before, we allocated the amount of memory required for storing a
_pointer_ to the thresholds data.  This crashed (at least) check_mysql
when using its "-S" option on FreeBSD/amd64 (as reported and analyzed by
Nikita Kalabukhov - 2797757).

Signed-off-by: Holger Weiss <holger@zedat.fu-berlin.de>
THANKS.in
lib/utils_base.c

index 189ba265d733840cb3fe944359526542f2d4ad47..aba48c6ba1c2bd73ba1d8c9b4d046258c3367f42 100644 (file)
--- a/THANKS.in
+++ b/THANKS.in
@@ -254,3 +254,4 @@ Ben Timby
 Martin Foster
 Joe Presbrey
 Will Preston
+Nikita Kalabukhov
index 77700f5ba7e46079d5abb68c042c0694c79a77eb..4303e1592700bc96cbc752930a157387215f56ad 100644 (file)
@@ -101,7 +101,9 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st
 {
        thresholds *temp_thresholds = NULL;
 
-       temp_thresholds = malloc(sizeof(temp_thresholds));
+       if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL)
+               die(STATE_UNKNOWN, _("Cannot allocate memory: %s\n"),
+                   strerror(errno));
 
        temp_thresholds->warning = NULL;
        temp_thresholds->critical = NULL;