Remove some duplicate free()s and add some that were missing.

Submitted by:	tmm
This commit is contained in:
Dag-Erling Smørgrav 2002-04-05 20:00:05 +00:00
parent 1e1404db2a
commit 40b93e6278

View File

@ -303,6 +303,7 @@ pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc,
if (auth_via_key(pamh, file, dotdir, pwent, pass) == if (auth_via_key(pamh, file, dotdir, pwent, pass) ==
PAM_SUCCESS) PAM_SUCCESS)
authenticated++; authenticated++;
free(dotdir);
free(keyfiles); free(keyfiles);
if (!authenticated) if (!authenticated)
return PAM_AUTH_ERR; return PAM_AUTH_ERR;
@ -346,6 +347,7 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
int no_link; /* link per-agent file? */ int no_link; /* link per-agent file? */
char *per_agent; /* to store env */ char *per_agent; /* to store env */
char *per_session; /* per-session filename */ char *per_session; /* per-session filename */
char *agent_pid; /* agent pid */
const struct passwd *pwent; /* user's passwd entry */ const struct passwd *pwent; /* user's passwd entry */
int retval; /* from calls */ int retval; /* from calls */
uid_t saved_uid; /* caller's uid */ uid_t saved_uid; /* caller's uid */
@ -416,7 +418,6 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
SSH_AGENT); SSH_AGENT);
if (env_write >= 0) if (env_write >= 0)
(void) close(env_write); (void) close(env_write);
free(per_agent);
return PAM_SESSION_ERR; return PAM_SESSION_ERR;
} }
} }
@ -448,7 +449,6 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
(void) close(env_write); (void) close(env_write);
if (agent_socket) if (agent_socket)
free(agent_socket); free(agent_socket);
free(per_agent);
return PAM_SERVICE_ERR; return PAM_SERVICE_ERR;
} }
@ -470,12 +470,12 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
(void) close(env_write); (void) close(env_write);
if (agent_socket) if (agent_socket)
free(agent_socket); free(agent_socket);
free(per_agent);
return PAM_SERVICE_ERR; return PAM_SERVICE_ERR;
} else if (strcmp(&env_string[strlen(env_string) - } else if (strcmp(&env_string[strlen(env_string) -
strlen(ENV_PID_SUFFIX)], ENV_PID_SUFFIX) == 0 && strlen(ENV_PID_SUFFIX)], ENV_PID_SUFFIX) == 0 &&
((agent_pid = strdup(env_value)) == NULL ||
(retval = pam_set_data(pamh, "ssh_agent_pid", (retval = pam_set_data(pamh, "ssh_agent_pid",
env_value, ssh_cleanup)) != PAM_SUCCESS) { agent_pid, ssh_cleanup)) != PAM_SUCCESS)) {
if (start_agent) if (start_agent)
(void) pclose(env_read); (void) pclose(env_read);
else else
@ -484,7 +484,8 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
(void) close(env_write); (void) close(env_write);
if (agent_socket) if (agent_socket)
free(agent_socket); free(agent_socket);
free(per_agent); if (agent_pid)
free(agent_pid);
return retval; return retval;
} }
@ -499,7 +500,6 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
SSH_AGENT); SSH_AGENT);
if (agent_socket) if (agent_socket)
free(agent_socket); free(agent_socket);
free(per_agent);
return PAM_SESSION_ERR; return PAM_SESSION_ERR;
case 0: case 0:
break; break;
@ -508,7 +508,6 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
MODULE_NAME, SSH_AGENT); MODULE_NAME, SSH_AGENT);
if (agent_socket) if (agent_socket)
free(agent_socket); free(agent_socket);
free(per_agent);
return PAM_SESSION_ERR; return PAM_SESSION_ERR;
default: default:
openpam_log(PAM_LOG_ERROR, "%s: %s exited %s %d", openpam_log(PAM_LOG_ERROR, "%s: %s exited %s %d",
@ -518,22 +517,17 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
WTERMSIG(retval) : WEXITSTATUS(retval)); WTERMSIG(retval) : WEXITSTATUS(retval));
if (agent_socket) if (agent_socket)
free(agent_socket); free(agent_socket);
free(per_agent);
return PAM_SESSION_ERR; return PAM_SESSION_ERR;
} }
} else } else
(void) fclose(env_read); (void) fclose(env_read);
if (!agent_socket) { if (!agent_socket)
free(per_agent);
return PAM_SESSION_ERR; return PAM_SESSION_ERR;
}
if (start_agent && (retval = add_keys(pamh, agent_socket)) if (start_agent && (retval = add_keys(pamh, agent_socket))
!= PAM_SUCCESS) { != PAM_SUCCESS)
free(per_agent);
return retval; return retval;
}
free(agent_socket); free(agent_socket);
/* if we couldn't access the per-agent file, don't link a /* if we couldn't access the per-agent file, don't link a
@ -546,14 +540,11 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
well as the hostname */ well as the hostname */
if ((retval = pam_get_item(pamh, PAM_TTY, (const void **)&tty)) if ((retval = pam_get_item(pamh, PAM_TTY, (const void **)&tty))
!= PAM_SUCCESS) { != PAM_SUCCESS)
free(per_agent);
return retval; return retval;
}
if (asprintf(&per_session, "%s/.ssh/agent-%s-%s", pwent->pw_dir, if (asprintf(&per_session, "%s/.ssh/agent-%s-%s", pwent->pw_dir,
hname, tty) == -1) { hname, tty) == -1) {
openpam_log(PAM_LOG_ERROR, "%s: %m", MODULE_NAME); openpam_log(PAM_LOG_ERROR, "%s: %m", MODULE_NAME);
free(per_agent);
return PAM_SERVICE_ERR; return PAM_SERVICE_ERR;
} }
@ -563,14 +554,11 @@ pam_sm_open_session(pam_handle_t *pamh, int flags, int argc,
if ((retval = pam_set_data(pamh, "ssh_agent_env_session", if ((retval = pam_set_data(pamh, "ssh_agent_env_session",
per_session, ssh_cleanup)) != PAM_SUCCESS) { per_session, ssh_cleanup)) != PAM_SUCCESS) {
free(per_session); free(per_session);
free(per_agent);
return retval; return retval;
} }
(void) unlink(per_session); /* remove cruft */ (void) unlink(per_session); /* remove cruft */
(void) link(per_agent, per_session); (void) link(per_agent, per_session);
free(per_agent);
free(per_session);
return PAM_SUCCESS; return PAM_SUCCESS;
} }