Przeglądaj źródła

Merge pull request #1278 from waja/github1227

Jan Wagner 12 lat temu
rodzic
commit
b43030cdd4
1 zmienionych plików z 10 dodań i 5 usunięć
  1. 10 5
      lib/utils_base.c

+ 10 - 5
lib/utils_base.c

@@ -446,6 +446,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
 	char *temp_filename = NULL;
 	char *temp_keyname = NULL;
 	char *p=NULL;
+	int ret;
 
 	if(this_monitoring_plugin==NULL)
 		die(STATE_UNKNOWN, _("This requires np_init to be called"));
@@ -476,9 +477,13 @@ void np_enable_state(char *keyname, int expected_data_version) {
 	this_state->state_data=NULL;
 
 	/* Calculate filename */
-	asprintf(&temp_filename, "%s/%lu/%s/%s",
+	ret = xasprintf(&temp_filename, "%s/%lu/%s/%s",
 	    _np_state_calculate_location_prefix(), (unsigned long)geteuid(),
 	    this_monitoring_plugin->plugin_name, this_state->name);
+	if (ret < 0)
+		die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
+		    strerror(errno));
+
 	this_state->_filename=temp_filename;
 
 	this_monitoring_plugin->state = this_state;
@@ -614,8 +619,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
 	
 	/* If file doesn't currently exist, create directories */
 	if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
-		asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
-		if(directories==NULL)
+		result = xasprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
+		if(result < 0)
 			die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
 			    strerror(errno));
 
@@ -633,8 +638,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
 		np_free(directories);
 	}
 
-	asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
-	if(temp_file==NULL)
+	result = xasprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
+	if(result < 0)
 		die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
 		    strerror(errno));