res_data = NULL;
cnt = 0;
val_cnt = 0;
- dr = NULL;
while(cur_date->before(max_date)) {
+ store = NULL;
+ dr = NULL;
if (period_type_param == PERIOD_YEARLY) {
store = new StoreCache(device_id, cur_date);
dr = store->get_mean(PERIOD_MONTHLY);
}
delete(dr);
}
- delete(store);
+ if (store != NULL)
+ delete(store);
if (period_type_param == PERIOD_YEARLY) {
cur_date->next_month();
}
case PERIOD_MINUTELY:
case PERIOD_SECONDLY:
if (StoreDay::exist(device_id, date, false)) {
- StoreDay *store;
+ StoreDay *store;
store = new StoreDay(device_id, date);
ret_val = store->get_mean(period_type_param);
res_data = NULL;
cnt = 0;
while(cur_date->before(max_date)) {
+ store = NULL;
+ dr = NULL;
if (period_type_param == PERIOD_YEARLY) {
store = new StoreCache(device_id, cur_date);
dr = store->get_max(PERIOD_MONTHLY);
}
delete(dr);
}
- delete(store);
+ if (store != NULL)
+ delete(store);
if (period_type_param == PERIOD_YEARLY) {
cur_date->next_month();
}
res_data = NULL;
cnt = 0;
while(cur_date->before(max_date)) {
+ store = NULL;
+ dr = NULL;
if (period_type_param == PERIOD_YEARLY) {
store = new StoreCache(device_id, cur_date);
dr = store->get_min(PERIOD_MONTHLY);
}
delete(dr);
}
- delete(store);
+ if (store != NULL)
+ delete(store);
if (period_type_param == PERIOD_YEARLY) {
cur_date->next_month();
}
int test_config() {
char work_dir[FILENAME_MAX];
char *val;
+ char *ret;
- getcwd(work_dir, sizeof(work_dir));
- printf("working directory: %s\n", work_dir);
+ ret = getcwd(work_dir, sizeof(work_dir));
+ if (ret != NULL) {
+ printf("working directory: %s\n", work_dir);
- set_config_value_and_save(work_dir,
- CONF_FILENAME,
- SECTION_TYPE,
- SECTION_NAME,
- KEY_NAME,
- VALUE1);
- val = get_config_value_and_close(work_dir,
- CONF_FILENAME,
- SECTION_NAME,
- KEY_NAME);
- if ((val != NULL) &&
- (strcmp(val, VALUE1) == 0)) {
- printf("value 1 read ok: %s\n", val);
- free(val);
- }
- else {
- printf("failed to read value\n");
- return 1;
- }
-
- val = get_config_value_and_close(work_dir,
+ set_config_value_and_save(work_dir,
+ CONF_FILENAME,
+ SECTION_TYPE,
+ SECTION_NAME,
+ KEY_NAME,
+ VALUE1);
+ val = get_config_value_and_close(work_dir,
CONF_FILENAME,
SECTION_NAME,
- KEY_NAME_INVALID_READ);
- if ((val != NULL) &&
- (strcmp(val, VALUE1) == 0)) {
- printf("pl, should not be possible to read invalid key value.\n");
- return 0;
- }
- else {
- printf("error, value was supposed to be NULL, but is: %s\n", val);
+ KEY_NAME);
+ if ((val != NULL) &&
+ (strcmp(val, VALUE1) == 0)) {
+ printf("value 1 read ok: %s\n", val);
+ free(val);
+ }
+ else {
+ printf("failed to read value\n");
+ return 1;
+ }
+
+ val = get_config_value_and_close(work_dir,
+ CONF_FILENAME,
+ SECTION_NAME,
+ KEY_NAME_INVALID_READ);
+ if ((val != NULL) &&
+ (strcmp(val, VALUE1) == 0)) {
+ printf("pl, should not be possible to read invalid key value.\n");
+ return 0;
+ }
+ else {
+ printf("error, value was supposed to be NULL, but is: %s\n", val);
+ }
+ set_config_value_and_save(work_dir,
+ CONF_FILENAME,
+ SECTION_TYPE,
+ SECTION_NAME,
+ KEY_NAME,
+ VALUE2);
+ set_config_value_and_save(work_dir,
+ CONF_FILENAME,
+ SECTION_TYPE,
+ SECTION_NAME,
+ KEY_NAME2,
+ VALUE3);
+ set_config_value_and_save(work_dir,
+ CONF_FILENAME,
+ SECTION_TYPE2,
+ SECTION_NAME2,
+ KEY_NAME3,
+ VALUE4);
}
- set_config_value_and_save(work_dir,
- CONF_FILENAME,
- SECTION_TYPE,
- SECTION_NAME,
- KEY_NAME,
- VALUE2);
- set_config_value_and_save(work_dir,
- CONF_FILENAME,
- SECTION_TYPE,
- SECTION_NAME,
- KEY_NAME2,
- VALUE3);
- set_config_value_and_save(work_dir,
- CONF_FILENAME,
- SECTION_TYPE2,
- SECTION_NAME2,
- KEY_NAME3,
- VALUE4);
return 0;
}