Skip to content

Commit 4a3aa4f

Browse files
committed
Less malloc/free
Simplify the DSS printing logic to prevent unnecessary malloc/free of temporary variables. Signed-off-by: George Bosilca <[email protected]>
1 parent 1ea8fab commit 4a3aa4f

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

opal/dss/dss_print.c

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -845,77 +845,53 @@ int opal_dss_print_name(char **output, char *prefix, opal_process_name_t *name,
845845
int opal_dss_print_jobid(char **output, char *prefix,
846846
opal_process_name_t *src, opal_data_type_t type)
847847
{
848-
char *prefx;
848+
char *prefx = " ";
849849

850850
/* deal with NULL prefix */
851-
if (NULL == prefix) asprintf(&prefx, " ");
852-
else prefx = prefix;
851+
if (NULL != prefix) prefx = prefix;
853852

854853
/* if src is NULL, just print data type and return */
855854
if (NULL == src) {
856855
asprintf(output, "%sData type: OPAL_JOBID\tValue: NULL pointer", prefx);
857-
if (prefx != prefix) {
858-
free(prefx);
859-
}
860856
return OPAL_SUCCESS;
861857
}
862858

863859
asprintf(output, "%sData type: OPAL_JOBID\tValue: %s", prefx, opal_jobid_print(src->jobid));
864-
if (prefx != prefix) {
865-
free(prefx);
866-
}
867-
868860
return OPAL_SUCCESS;
869861
}
870862

871863
int opal_dss_print_vpid(char **output, char *prefix,
872864
opal_process_name_t *src, opal_data_type_t type)
873865
{
874-
char *prefx;
866+
char *prefx = " ";
875867

876868
/* deal with NULL prefix */
877-
if (NULL == prefix) asprintf(&prefx, " ");
878-
else prefx = prefix;
869+
if (NULL != prefix) prefx = prefix;
879870

880871
/* if src is NULL, just print data type and return */
881872
if (NULL == src) {
882873
asprintf(output, "%sData type: OPAL_VPID\tValue: NULL pointer", prefx);
883-
if (prefx != prefix) {
884-
free(prefx);
885-
}
886874
return OPAL_SUCCESS;
887875
}
888876

889877
asprintf(output, "%sData type: OPAL_VPID\tValue: %s", prefx, opal_vpid_print(src->vpid));
890-
if (prefx != prefix) {
891-
free(prefx);
892-
}
893-
894878
return OPAL_SUCCESS;
895879
}
896880

897881
int opal_dss_print_status(char **output, char *prefix,
898882
int *src, opal_data_type_t type)
899883
{
900-
char *prefx;
884+
char *prefx = " ";
901885

902886
/* deal with NULL prefix */
903-
if (NULL == prefix) asprintf(&prefx, " ");
904-
else prefx = prefix;
887+
if (NULL != prefix) prefx = prefix;
905888

906889
/* if src is NULL, just print data type and return */
907890
if (NULL == src) {
908891
asprintf(output, "%sData type: OPAL_STATUS\tValue: NULL pointer", prefx);
909-
if (prefx != prefix) {
910-
free(prefx);
911-
}
912892
return OPAL_SUCCESS;
913893
}
914894

915895
asprintf(output, "%sData type: OPAL_STATUS\tValue: %s", prefx, opal_strerror(*src));
916-
if (prefx != prefix) {
917-
free(prefx);
918-
}
919-
920896
return OPAL_SUCCESS;
921897
}

0 commit comments

Comments
 (0)