- if(parse_keys(name, dset_name, ds_name))
- {
- return 1;
- }
- idx = get_matching_dset(d, dset_name);
- if(idx == -1)
- {/* need to add a dset **/
- dset_array = realloc(d->dset,
- sizeof(struct data_set_s) * (d->dset_num + 1));
- if(!dset_array)
- {
- return -ENOMEM;
- }
- pc_types_array = realloc(d->pc_types,
- sizeof(int *) * (d->dset_num + 1));
- if(!pc_types_array)
- {
- return -ENOMEM;
- }
- dset = &dset_array[d->dset_num];
- /** this step is very important, otherwise,
- * realloc for dset->ds will tricky because of
- * a random addr in dset->ds
- */
- memset(dset, 0, sizeof(struct data_set_s));
- dset->ds_num = 0;
- snprintf(dset->type, DATA_MAX_NAME_LEN, "%s", dset_name);
- pc_types = pc_types_array[d->dset_num] = NULL;
- d->dset = dset_array;
- }
- else
- {
- dset = &d->dset[idx];
- pc_types = d->pc_types[idx];
- }
- struct data_source_s *ds_array = realloc(dset->ds,
- sizeof(struct data_source_s) * (dset->ds_num + 1));
- if(!ds_array)
- {
- return -ENOMEM;
- }
- pc_types_new = realloc(pc_types, sizeof(int) * (dset->ds_num + 1));
- if(!pc_types_new)
- {
- return -ENOMEM;
- }
- dset->ds = ds_array;