- if (lost_pids && lost_pids_count > 0) {
- pid_t lost_pids_array[lost_pids_count];
- pids_list_to_array(lost_pids_array, lost_pids,
- STATIC_ARRAY_SIZE(lost_pids_array));
-
- if (lost_pids_count == ngroup->monitored_pids_count) {
- /* all pids for this group are lost: stop monitoring */
- int stop_result = pqos_mon_stop(group_mon_data);
- if (PQOS_RETVAL_OK != stop_result) {
- ERROR(RDT_PLUGIN ": rdt_refresh_ngroup: \'%s\'. Error [%d] while "
- "STOPPING monitoring",
- ngroup->desc, stop_result);
- result = -1;
- goto pqos_error_recovery;
- }
- ngroup->monitored_pids_count = 0;
+ if (lost_pids && lost_pids_count > 0) {
+ lost_pids_array = malloc(lost_pids_count * sizeof(pid_t));
+ if (lost_pids_array == NULL) {
+ ERROR(RDT_PLUGIN ": rdt_refresh_ngroup: \'%s\'. Memory "
+ "allocation failed",
+ ngroup->desc);
+ result = -1;
+ goto cleanup;
+ }
+ pids_list_to_array(lost_pids_array, lost_pids, lost_pids_count);
+
+ if (lost_pids_count == ngroup->monitored_pids_count) {
+ /* all pids for this group are lost: stop monitoring */
+ int stop_result = pqos_mon_stop(group_mon_data);
+ if (PQOS_RETVAL_OK != stop_result) {
+ ERROR(RDT_PLUGIN ": rdt_refresh_ngroup: \'%s\'. Error [%d] while "
+ "STOPPING monitoring",
+ ngroup->desc, stop_result);
+ result = -1;
+ goto pqos_error_recovery;
+ }
+ ngroup->monitored_pids_count = 0;
+ } else {
+ assert(lost_pids_count < ngroup->monitored_pids_count);
+ int remove_result = pqos_mon_remove_pids(lost_pids_count, lost_pids_array,
+ group_mon_data);
+ if (PQOS_RETVAL_OK == remove_result) {
+ ngroup->monitored_pids_count -= lost_pids_count;