[mpich-discuss] Hydra genv_fn() memory leaks fix

Yauheni Zelenko zelenko at cadence.com
Mon Aug 2 16:48:04 CDT 2010


Hi!

I want to suggest fix for memory leaks in genv_fn(). Code is based on r6973. Please review code.

I also wonder with adding environment to list is so complicated and involve several memory copies (strings and structures)? May be should just HYDU_append_env_to_list() use name and value arguments instead of intermediate environment structure?

static HYD_status genv_fn(char *arg, char ***argv)
{
    char *env_name, *env_value, *str[2] = { NULL, NULL };
    struct HYD_env *env;
    HYD_status status = HYD_SUCCESS;

    status = HYDU_strsplit(**argv, &str[0], &str[1], '=');
    HYDU_ERR_POP(status, "string break returned error\n");
    (*argv)++;

    env_name = str[0];
    if (str[1] == NULL) {       /* The environment is not of the form x=foo */
        if (**argv == NULL) {
            status = HYD_INTERNAL_ERROR;
            goto fn_fail;
        }
        env_value = **argv;
        (*argv)++;
    }
    else {
        env_value = str[1];
    }

    status = HYDU_env_create(&env, env_name, env_value);
    HYDU_ERR_POP(status, "unable to create env struct\n");

    HYDU_append_env_to_list(*env, &HYD_handle.user_global.global_env.user);

  fn_exit:

    if (str[0])
	HYDU_free(str[0]);
    if (str[1])
	HYDU_free(str[1]);
    if (env)
	HYDU_env_free(env);

    return status;

  fn_fail:
    goto fn_exit;
}

Eugene.


More information about the mpich-discuss mailing list