From 9cb455272b27c46996ecd7904452d163efdecf7d Mon Sep 17 00:00:00 2001 From: Tim Prins Date: Thu, 29 Mar 2007 00:50:56 +0000 Subject: [PATCH] Fix a pile of memory leaks in ORTE. Fix a major memory leak in the SLURM RAS, and cleanup a bit of code there. This commit was SVN r14164. --- orte/mca/pls/slurm/pls_slurm_module.c | 13 ++++-- orte/mca/ras/slurm/ras_slurm_module.c | 45 +++++++++---------- orte/mca/rds/base/rds_base_close.c | 6 ++- orte/mca/rds/base/rds_base_open.c | 3 +- orte/mca/rmaps/base/rmaps_base_registry_fns.c | 3 ++ orte/mca/rmaps/round_robin/rmaps_rr.c | 4 +- orte/util/pre_condition_transports.c | 1 + 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/orte/mca/pls/slurm/pls_slurm_module.c b/orte/mca/pls/slurm/pls_slurm_module.c index 3bdecec163..aa03985885 100644 --- a/orte/mca/pls/slurm/pls_slurm_module.c +++ b/orte/mca/pls/slurm/pls_slurm_module.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University @@ -120,13 +120,13 @@ static int pls_slurm_launch_job(orte_jobid_t jobid) size_t num_nodes; orte_vpid_t vpid; orte_vpid_t start_vpid; - char *jobid_string; + char *jobid_string = NULL; char *uri, *param; char **argv; int argc; int rc; char *tmp; - char** env; + char** env = NULL; char* var; char *nodelist_flat; char **nodelist_argv; @@ -246,6 +246,7 @@ static int pls_slurm_launch_job(orte_jobid_t jobid) opal_argv_append(&nodelist_argc, &nodelist_argv, node->nodename); } nodelist_flat = opal_argv_join(nodelist_argv, ','); + opal_argv_free(nodelist_argv); asprintf(&tmp, "--nodelist=%s", nodelist_flat); opal_argv_append(&argc, &argv, tmp); free(tmp); @@ -435,6 +436,12 @@ static int pls_slurm_launch_job(orte_jobid_t jobid) cleanup: OBJ_RELEASE(map); + opal_argv_free(argv); + opal_argv_free(env); + + if(NULL != jobid_string) { + free(jobid_string); + } while (NULL != (item = opal_list_remove_first(&daemons))) { OBJ_RELEASE(item); diff --git a/orte/mca/ras/slurm/ras_slurm_module.c b/orte/mca/ras/slurm/ras_slurm_module.c index 568a62b0d5..2a59067a64 100644 --- a/orte/mca/ras/slurm/ras_slurm_module.c +++ b/orte/mca/ras/slurm/ras_slurm_module.c @@ -166,7 +166,7 @@ static int orte_ras_slurm_discover(char *regexp, char *tasks_per_node, opal_list_t* nodelist) { int i, j, len, ret, count, reps, num_nodes; - char *base, **names = NULL, *temp; + char *base, **names = NULL; char *begptr, *endptr, *orig; int *slots; bool found_range = false; @@ -248,12 +248,7 @@ static int orte_ras_slurm_discover(char *regexp, char *tasks_per_node, /* If we didn't find a range, just add the node */ opal_output(orte_ras_base.ras_output, "ras:slurm:allocate:discover: found node %s", base); - if(NULL == (temp = strdup(base))) { - ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); - free(orig); - return ORTE_ERR_OUT_OF_RESOURCE; - } - if(ORTE_SUCCESS != (ret = opal_argv_append_nosize(&names, temp))) { + if(ORTE_SUCCESS != (ret = opal_argv_append_nosize(&names, base))) { ORTE_ERROR_LOG(ret); free(orig); return ret; @@ -423,9 +418,9 @@ static int orte_ras_slurm_parse_ranges(char *base, char *ranges, char ***names) */ static int orte_ras_slurm_parse_range(char *base, char *range, char ***names) { - char *str, temp1[BUFSIZ], temp2[BUFSIZ]; + char *str, temp1[BUFSIZ]; size_t i, j, start, end; - size_t base_len, len; + size_t base_len, len, num_len; size_t str_start, str_end; size_t num_str_len; bool found; @@ -490,34 +485,34 @@ static int orte_ras_slurm_parse_range(char *base, char *range, char ***names) /* Make strings for all values in the range */ + len = base_len + num_str_len + 32; + str = malloc(len); + if (NULL == str) { + ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); + return ORTE_ERR_OUT_OF_RESOURCE; + } + strcpy(str, base); for (i = start; i <= end; ++i) { - len = base_len + 32; - str = malloc(len); - if (NULL == str) { - ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); - return ORTE_ERR_OUT_OF_RESOURCE; - } - - str[0] = '\0'; - snprintf(temp1, BUFSIZ - 1, "%s", base); - snprintf(temp2, BUFSIZ - 1, "%lu", (long) i); - temp1[BUFSIZ - 1] = temp2[BUFSIZ - 1] = '\0'; + str[base_len] = '\0'; + snprintf(temp1, BUFSIZ - 1, "%lu", (long) i); /* Do we need zero pading? */ - if (strlen(temp2) < num_str_len) { - for (j = 0; j < num_str_len - strlen(temp2); ++j) { - strcat(temp1, "0"); + if ((num_len = strlen(temp1)) < num_str_len) { + for (j = base_len; j < base_len + (num_str_len - num_len); ++j) { + str[j] = '0'; } + str[j] = '\0'; } - snprintf(str, len - 1, "%s%s", temp1, temp2); - str[len - 1] = '\0'; + strcat(str, temp1); ret = opal_argv_append_nosize(names, str); if(ORTE_SUCCESS != ret) { ORTE_ERROR_LOG(ret); + free(str); return ret; } } + free(str); /* All done */ return ORTE_SUCCESS; diff --git a/orte/mca/rds/base/rds_base_close.c b/orte/mca/rds/base/rds_base_close.c index 0ca0b46677..e3d89342ac 100644 --- a/orte/mca/rds/base/rds_base_close.c +++ b/orte/mca/rds/base/rds_base_close.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2005 The University of Tennessee and The University @@ -74,6 +74,10 @@ int orte_rds_base_close(void) mca_base_components_close(orte_rds_base.rds_output, &orte_rds_base.rds_components, NULL); + if(-1 != orte_rds_base.rds_output) { + opal_output_close(orte_rds_base.rds_output); + } + OBJ_DESTRUCT(&orte_rds_base.rds_selected); return ORTE_SUCCESS; } diff --git a/orte/mca/rds/base/rds_base_open.c b/orte/mca/rds/base/rds_base_open.c index bf30a72ac4..f8a33d3052 100644 --- a/orte/mca/rds/base/rds_base_open.c +++ b/orte/mca/rds/base/rds_base_open.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2005 The University of Tennessee and The University @@ -113,7 +113,6 @@ int orte_rds_base_open(void) /* Debugging / verbose output */ - orte_rds_base.rds_output = opal_output_open(NULL); param = mca_base_param_reg_int_name("rds_base", "verbose", "Verbosity level for the rds framework", false, false, 0, &value); diff --git a/orte/mca/rmaps/base/rmaps_base_registry_fns.c b/orte/mca/rmaps/base/rmaps_base_registry_fns.c index 0155f61736..3d506e0e94 100644 --- a/orte/mca/rmaps/base/rmaps_base_registry_fns.c +++ b/orte/mca/rmaps/base/rmaps_base_registry_fns.c @@ -552,6 +552,9 @@ cleanup: OBJ_RELEASE(values[i]); } } + if(NULL != segment) { + free(segment); + } if(NULL != values) free(values); return rc; diff --git a/orte/mca/rmaps/round_robin/rmaps_rr.c b/orte/mca/rmaps/round_robin/rmaps_rr.c index 9facfc7094..c97c915490 100644 --- a/orte/mca/rmaps/round_robin/rmaps_rr.c +++ b/orte/mca/rmaps/round_robin/rmaps_rr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2006 The University of Tennessee and The University @@ -758,6 +758,8 @@ cleanup: OBJ_DESTRUCT(&max_used_nodes); OBJ_DESTRUCT(&fully_used_nodes); OBJ_DESTRUCT(&mapped_node_list); + OBJ_RELEASE(map); + free(save_bookmark); diff --git a/orte/util/pre_condition_transports.c b/orte/util/pre_condition_transports.c index df667bb678..d4eb7580cd 100644 --- a/orte/util/pre_condition_transports.c +++ b/orte/util/pre_condition_transports.c @@ -154,6 +154,7 @@ int orte_pre_condition_transports(orte_app_context_t **app_context, size_t num_c } free(cs_env); + free(format); free(string_key); return ORTE_SUCCESS;