Skip to content

Commit f6e932c

Browse files
committed
Fix memory corruption in orte-ps
orte-ps ends up free'ing the same pointer multiple times
1 parent 6d7ada9 commit f6e932c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

orte/tools/orte-ps/orte-ps.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static int pretty_print_vpids(orte_job_t *job) {
651651
char *snap_ref = NULL;
652652
char *snap_loc = NULL;
653653
#endif
654-
char *nodename;
654+
char **nodename;
655655

656656
/*
657657
* Caculate segment lengths
@@ -672,6 +672,7 @@ static int pretty_print_vpids(orte_job_t *job) {
672672
len_ckpt_l = -3;
673673
#endif
674674

675+
nodename = (char **) malloc(job->num_procs * sizeof(char *));
675676
for(v=0; v < job->num_procs; v++) {
676677
char *rankstr;
677678
vpid = (orte_proc_t*)job->procs->addr[v];
@@ -707,10 +708,10 @@ static int pretty_print_vpids(orte_job_t *job) {
707708
len_rank = strlen(rankstr);
708709
free(rankstr);
709710

710-
nodename = NULL;
711-
if( orte_get_attribute(&vpid->attributes, ORTE_PROC_NODENAME, (void**)&nodename, OPAL_STRING) &&
712-
(int)strlen(nodename) > len_node) {
713-
len_node = strlen(nodename);
711+
nodename[v] = NULL;
712+
if( orte_get_attribute(&vpid->attributes, ORTE_PROC_NODENAME, (void**)&nodename[v], OPAL_STRING) &&
713+
(int)strlen(nodename[v]) > len_node) {
714+
len_node = strlen(nodename[v]);
714715
} else if ((int)strlen("Unknown") > len_node) {
715716
len_node = strlen("Unknown");
716717
}
@@ -793,12 +794,12 @@ static int pretty_print_vpids(orte_job_t *job) {
793794
printf("%*s | ", len_o_proc_name, o_proc_name);
794795
printf("%*u | ", len_rank , (uint)vpid->local_rank);
795796
printf("%*d | ", len_pid , vpid->pid);
796-
printf("%*s | ", len_node , (NULL == nodename) ? "Unknown" : nodename);
797-
if (NULL != nodename) {
798-
free(nodename);
799-
}
797+
printf("%*s | ", len_node , (NULL == nodename[v]) ? "Unknown" : nodename[v]);
800798
printf("%*s | ", len_state , orte_proc_state_to_str(vpid->state));
801799

800+
if (NULL != nodename[v]) {
801+
free(nodename[v]);
802+
}
802803
#if OPAL_ENABLE_FT_CR == 1
803804
printf("%*s | ", len_ckpt_s, state_str);
804805
printf("%*s | ", len_ckpt_r, (NULL == snap_ref ? "" : snap_ref));

0 commit comments

Comments
 (0)