1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Joe Yates's memory leak patches.

[originally from svn r3650]
This commit is contained in:
Simon Tatham 2003-12-19 12:44:46 +00:00
parent 20bc740780
commit 7a1eae7ff2
10 changed files with 118 additions and 8 deletions

View File

@ -51,6 +51,14 @@ static void cmdline_save_param(char *p, char *value, int pri)
saves[pri].nsaved++; saves[pri].nsaved++;
} }
void cmdline_cleanup(void)
{
int pri;
for (pri = 0; pri < NPRIORITIES; pri++)
sfree(saves[pri].params);
}
#define SAVEABLE(pri) do { \ #define SAVEABLE(pri) do { \
if (need_save) { cmdline_save_param(p, value, pri); return ret; } \ if (need_save) { cmdline_save_param(p, value, pri); return ret; } \
} while (0) } while (0)

50
psftp.c
View File

@ -25,6 +25,7 @@
static int psftp_connect(char *userhost, char *user, int portnumber); static int psftp_connect(char *userhost, char *user, int portnumber);
static int do_sftp_init(void); static int do_sftp_init(void);
void do_sftp_cleanup();
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------
* sftp client state. * sftp client state.
@ -1404,8 +1405,8 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
*/ */
cmd->nwords = cmd->wordssize = 2; cmd->nwords = cmd->wordssize = 2;
cmd->words = sresize(cmd->words, cmd->wordssize, char *); cmd->words = sresize(cmd->words, cmd->wordssize, char *);
cmd->words[0] = "!"; cmd->words[0] = dupstr("!");
cmd->words[1] = p+1; cmd->words[1] = dupstr(p+1);
} else { } else {
/* /*
@ -1448,10 +1449,11 @@ struct sftp_command *sftp_getcmd(FILE *fp, int mode, int modeflags)
cmd->wordssize = cmd->nwords + 16; cmd->wordssize = cmd->nwords + 16;
cmd->words = sresize(cmd->words, cmd->wordssize, char *); cmd->words = sresize(cmd->words, cmd->wordssize, char *);
} }
cmd->words[cmd->nwords++] = q; cmd->words[cmd->nwords++] = dupstr(q);
} }
} }
sfree(line);
/* /*
* Now parse the first word and assign a function. * Now parse the first word and assign a function.
*/ */
@ -1504,6 +1506,23 @@ static int do_sftp_init(void)
return 0; return 0;
} }
void do_sftp_cleanup()
{
char ch;
back->special(backhandle, TS_EOF);
sftp_recvdata(&ch, 1);
back->free(backhandle);
sftp_cleanup_request();
if (pwd) {
sfree(pwd);
pwd = NULL;
}
if (homedir) {
sfree(homedir);
homedir = NULL;
}
}
void do_sftp(int mode, int modeflags, char *batchfile) void do_sftp(int mode, int modeflags, char *batchfile)
{ {
FILE *fp; FILE *fp;
@ -1522,7 +1541,15 @@ void do_sftp(int mode, int modeflags, char *batchfile)
cmd = sftp_getcmd(stdin, 0, 0); cmd = sftp_getcmd(stdin, 0, 0);
if (!cmd) if (!cmd)
break; break;
if (cmd->obey(cmd) < 0) ret = cmd->obey(cmd);
if (cmd->words) {
int i;
for(i = 0; i < cmd->nwords; i++)
sfree(cmd->words[i]);
sfree(cmd->words);
}
sfree(cmd);
if (ret < 0)
break; break;
} }
} else { } else {
@ -1908,6 +1935,8 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
} }
if (verbose && realhost != NULL) if (verbose && realhost != NULL)
printf("Connected to %s\n", realhost); printf("Connected to %s\n", realhost);
if (realhost != NULL)
sfree(realhost);
return 0; return 0;
} }
@ -1993,13 +2022,16 @@ int psftp_main(int argc, char *argv[])
* it now. * it now.
*/ */
if (userhost) { if (userhost) {
if (psftp_connect(userhost, user, portnumber)) int ret;
ret = psftp_connect(userhost, user, portnumber);
sfree(userhost);
if (ret)
return 1; return 1;
if (do_sftp_init()) if (do_sftp_init())
return 1; return 1;
} else { } else {
printf("psftp: no hostname specified; use \"open host.name\"" printf("psftp: no hostname specified; use \"open host.name\""
" to connect\n"); " to connect\n");
} }
do_sftp(mode, modeflags, batchfile); do_sftp(mode, modeflags, batchfile);
@ -2010,6 +2042,12 @@ int psftp_main(int argc, char *argv[])
sftp_recvdata(&ch, 1); sftp_recvdata(&ch, 1);
} }
random_save_seed(); random_save_seed();
cmdline_cleanup();
console_provide_logctx(NULL);
do_sftp_cleanup();
backhandle = NULL;
back = NULL;
sk_cleanup();
return 0; return 0;
} }

View File

@ -814,6 +814,7 @@ void printer_finish_job(printer_job *);
*/ */
int cmdline_process_param(char *, char *, int, Config *); int cmdline_process_param(char *, char *, int, Config *);
void cmdline_run_saved(Config *); void cmdline_run_saved(Config *);
void cmdline_cleanup(void);
extern char *cmdline_password; extern char *cmdline_password;
#define TOOLTYPE_FILETRANSFER 1 #define TOOLTYPE_FILETRANSFER 1
#define TOOLTYPE_NONNETWORK 2 #define TOOLTYPE_NONNETWORK 2

6
scp.c
View File

@ -2178,6 +2178,12 @@ int psftp_main(int argc, char *argv[])
if (gui_mode) if (gui_mode)
gui_send_errcount(list, errs); gui_send_errcount(list, errs);
cmdline_cleanup();
console_provide_logctx(NULL);
back->free(backhandle);
backhandle = NULL;
back = NULL;
sk_cleanup();
return (errs == 0 ? 0 : 1); return (errs == 0 ? 0 : 1);
} }

8
sftp.c
View File

@ -334,6 +334,14 @@ static struct sftp_request *sftp_alloc_request(void)
return r; return r;
} }
void sftp_cleanup_request(void)
{
if (sftp_requests == NULL) {
freetree234(sftp_requests);
sftp_requests = NULL;
}
}
void sftp_register(struct sftp_request *req) void sftp_register(struct sftp_request *req)
{ {
req->registered = 1; req->registered = 1;

5
sftp.h
View File

@ -67,6 +67,11 @@
int sftp_senddata(char *data, int len); int sftp_senddata(char *data, int len);
int sftp_recvdata(char *data, int len); int sftp_recvdata(char *data, int len);
/*
* Free sftp_requests
*/
void sftp_cleanup_request(void);
struct fxp_attrs { struct fxp_attrs {
unsigned long flags; unsigned long flags;
uint64 size; uint64 size;

38
ssh.c
View File

@ -2535,6 +2535,22 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
ssh->crcda_ctx = crcda_make_context(); ssh->crcda_ctx = crcda_make_context();
logevent("Installing CRC compensation attack detector"); logevent("Installing CRC compensation attack detector");
if (servkey.modulus) {
sfree(servkey.modulus);
servkey.modulus = NULL;
}
if (servkey.exponent) {
sfree(servkey.exponent);
servkey.exponent = NULL;
}
if (hostkey.modulus) {
sfree(hostkey.modulus);
hostkey.modulus = NULL;
}
if (hostkey.exponent) {
sfree(hostkey.exponent);
hostkey.exponent = NULL;
}
crWaitUntil(ispkt); crWaitUntil(ispkt);
if (ssh->pktin.type != SSH1_SMSG_SUCCESS) { if (ssh->pktin.type != SSH1_SMSG_SUCCESS) {
@ -3037,6 +3053,7 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, int ispkt)
} }
logevent("Sending password with camouflage packets"); logevent("Sending password with camouflage packets");
ssh_pkt_defersend(ssh); ssh_pkt_defersend(ssh);
sfree(randomstr);
} }
else if (!(ssh->remote_bugs & BUG_NEEDS_SSH1_PLAIN_PASSWORD)) { else if (!(ssh->remote_bugs & BUG_NEEDS_SSH1_PLAIN_PASSWORD)) {
/* /*
@ -4338,6 +4355,10 @@ static int do_ssh2_transport(Ssh ssh, unsigned char *in, int inlen, int ispkt)
if (ssh->sccomp->text_name) if (ssh->sccomp->text_name)
logeventf(ssh, "Initialised %s decompression", logeventf(ssh, "Initialised %s decompression",
ssh->sccomp->text_name); ssh->sccomp->text_name);
freebn(s->f);
freebn(s->g);
freebn(s->K);
freebn(s->p);
/* /*
* If this is the first key exchange phase, we must pass the * If this is the first key exchange phase, we must pass the
@ -6278,7 +6299,22 @@ static void ssh_free(void *handle)
sfree(ssh->do_ssh1_login_state); sfree(ssh->do_ssh1_login_state);
sfree(ssh->do_ssh2_transport_state); sfree(ssh->do_ssh2_transport_state);
sfree(ssh->do_ssh2_authconn_state); sfree(ssh->do_ssh2_authconn_state);
if (ssh->pktout.data) {
sfree(ssh->pktout.data);
ssh->pktout.data = NULL;
}
if (ssh->pktin.data) {
sfree(ssh->pktin.data);
ssh->pktin.data = NULL;
}
if (ssh->crcda_ctx) {
crcda_free_context(ssh->crcda_ctx);
ssh->crcda_ctx = NULL;
}
if (ssh->logctx) {
log_free(ssh->logctx);
ssh->logctx = NULL;
}
if (ssh->s) if (ssh->s)
ssh_do_close(ssh); ssh_do_close(ssh);
sfree(ssh); sfree(ssh);

View File

@ -71,7 +71,12 @@ void *crcda_make_context(void)
void crcda_free_context(void *handle) void crcda_free_context(void *handle)
{ {
sfree(handle); struct crcda_ctx *ctx = (struct crcda_ctx *)handle;
if (ctx) {
sfree(ctx->h);
ctx->h = NULL;
sfree(ctx);
}
} }
static void crc_update(uint32 *a, void *b) static void crc_update(uint32 *a, void *b)

View File

@ -738,6 +738,7 @@ static int rsa2_verifysig(void *key, char *sig, int siglen,
if (bignum_byte(out, i) != hash[j]) if (bignum_byte(out, i) != hash[j])
ret = 0; ret = 0;
} }
freebn(out);
return ret; return ret;
} }

View File

@ -237,6 +237,8 @@ void sk_cleanup(void)
for (i = 0; (s = index234(sktree, i)) != NULL; i++) { for (i = 0; (s = index234(sktree, i)) != NULL; i++) {
p_closesocket(s->s); p_closesocket(s->s);
} }
freetree234(sktree);
sktree = NULL;
} }
p_WSACleanup(); p_WSACleanup();