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

Plug a few minor memory leaks, based on a patch by Sirp Potijk.

While I'm here, add an assertion in sshrand.c to catch mistakes in reference
counting.

[originally from svn r8846]
This commit is contained in:
Jacob Nevins 2010-01-17 16:20:45 +00:00
parent 99455bfc33
commit 5ea11dfb3a
3 changed files with 22 additions and 3 deletions

View File

@ -56,20 +56,30 @@ static void cmdline_save_param(char *p, char *value, int pri)
saves[pri].nsaved++; saves[pri].nsaved++;
} }
static char *cmdline_password = NULL;
void cmdline_cleanup(void) void cmdline_cleanup(void)
{ {
int pri; int pri;
for (pri = 0; pri < NPRIORITIES; pri++) if (cmdline_password) {
memset(cmdline_password, 0, strlen(cmdline_password));
sfree(cmdline_password);
cmdline_password = NULL;
}
for (pri = 0; pri < NPRIORITIES; pri++) {
sfree(saves[pri].params); sfree(saves[pri].params);
saves[pri].params = NULL;
saves[pri].savesize = 0;
saves[pri].nsaved = 0;
}
} }
#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)
static char *cmdline_password = NULL;
/* /*
* Similar interface to get_userpass_input(), except that here a -1 * Similar interface to get_userpass_input(), except that here a -1
* return means that we aren't capable of processing the prompt and * return means that we aren't capable of processing the prompt and
@ -99,6 +109,8 @@ int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) {
p->prompts[0]->result_len); p->prompts[0]->result_len);
p->prompts[0]->result[p->prompts[0]->result_len-1] = '\0'; p->prompts[0]->result[p->prompts[0]->result_len-1] = '\0';
memset(cmdline_password, 0, strlen(cmdline_password)); memset(cmdline_password, 0, strlen(cmdline_password));
sfree(cmdline_password);
cmdline_password = NULL;
tried_once = 1; tried_once = 1;
return 1; return 1;

2
ssh.c
View File

@ -2853,6 +2853,8 @@ static int ssh_do_close(Ssh ssh, int notify_exit)
del234(ssh->portfwds, pf); /* moving next one to index 0 */ del234(ssh->portfwds, pf); /* moving next one to index 0 */
free_portfwd(pf); free_portfwd(pf);
} }
freetree234(ssh->portfwds);
ssh->portfwds = NULL;
} }
return ret; return ret;

View File

@ -4,6 +4,7 @@
#include "putty.h" #include "putty.h"
#include "ssh.h" #include "ssh.h"
#include <assert.h>
/* Collect environmental noise every 5 minutes */ /* Collect environmental noise every 5 minutes */
#define NOISE_REGULAR_INTERVAL (5*60*TICKSPERSEC) #define NOISE_REGULAR_INTERVAL (5*60*TICKSPERSEC)
@ -225,6 +226,10 @@ void random_ref(void)
void random_unref(void) void random_unref(void)
{ {
random_active--; random_active--;
assert(random_active >= 0);
if (random_active) return;
expire_timer_context(&pool);
} }
int random_byte(void) int random_byte(void)