summaryrefslogtreecommitdiffstats
path: root/lib/utils_base.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils_base.c')
-rw-r--r--lib/utils_base.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/utils_base.c b/lib/utils_base.c
index addf26b..3822bcf 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -446,6 +446,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
446 char *temp_filename = NULL; 446 char *temp_filename = NULL;
447 char *temp_keyname = NULL; 447 char *temp_keyname = NULL;
448 char *p=NULL; 448 char *p=NULL;
449 int ret;
449 450
450 if(this_monitoring_plugin==NULL) 451 if(this_monitoring_plugin==NULL)
451 die(STATE_UNKNOWN, _("This requires np_init to be called")); 452 die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -476,9 +477,13 @@ void np_enable_state(char *keyname, int expected_data_version) {
476 this_state->state_data=NULL; 477 this_state->state_data=NULL;
477 478
478 /* Calculate filename */ 479 /* Calculate filename */
479 asprintf(&temp_filename, "%s/%lu/%s/%s", 480 ret = asprintf(&temp_filename, "%s/%lu/%s/%s",
480 _np_state_calculate_location_prefix(), (unsigned long)geteuid(), 481 _np_state_calculate_location_prefix(), (unsigned long)geteuid(),
481 this_monitoring_plugin->plugin_name, this_state->name); 482 this_monitoring_plugin->plugin_name, this_state->name);
483 if (ret < 0)
484 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
485 strerror(errno));
486
482 this_state->_filename=temp_filename; 487 this_state->_filename=temp_filename;
483 488
484 this_monitoring_plugin->state = this_state; 489 this_monitoring_plugin->state = this_state;
@@ -614,8 +619,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
614 619
615 /* If file doesn't currently exist, create directories */ 620 /* If file doesn't currently exist, create directories */
616 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) { 621 if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
617 asprintf(&directories, "%s", this_monitoring_plugin->state->_filename); 622 result = asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
618 if(directories==NULL) 623 if(result < 0)
619 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 624 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
620 strerror(errno)); 625 strerror(errno));
621 626
@@ -633,8 +638,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
633 np_free(directories); 638 np_free(directories);
634 } 639 }
635 640
636 asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename); 641 result = asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
637 if(temp_file==NULL) 642 if(result < 0)
638 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"), 643 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
639 strerror(errno)); 644 strerror(errno));
640 645