mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 11:02:48 -05:00
Fix another giant batch of resource leaks. (Mostly memory, but there's
one missing fclose too.) [originally from svn r9919]
This commit is contained in:
@ -191,8 +191,10 @@ static char *x11_guess_derived_font_name(XFontStruct *xfs, int bold, int wide)
|
||||
p++;
|
||||
}
|
||||
|
||||
if (nstr < lenof(strings))
|
||||
if (nstr < lenof(strings)) {
|
||||
sfree(dupname);
|
||||
return NULL; /* XLFD was malformed */
|
||||
}
|
||||
|
||||
if (bold)
|
||||
strings[2] = "bold";
|
||||
|
@ -3009,7 +3009,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data)
|
||||
4, 12, 5, 13, 6, 14, 7, 15
|
||||
};
|
||||
struct gui_data *inst = (struct gui_data *)data;
|
||||
char *title = dupcat(appname, " Reconfiguration", NULL);
|
||||
char *title;
|
||||
Conf *oldconf, *newconf;
|
||||
int i, j, need_size;
|
||||
|
||||
@ -3020,6 +3020,8 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data)
|
||||
else
|
||||
inst->reconfiguring = TRUE;
|
||||
|
||||
title = dupcat(appname, " Reconfiguration", NULL);
|
||||
|
||||
oldconf = inst->conf;
|
||||
newconf = conf_copy(inst->conf);
|
||||
|
||||
@ -3134,6 +3136,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data)
|
||||
string_width("Could not change fonts in terminal window:"),
|
||||
"OK", 'o', +1, 1,
|
||||
NULL);
|
||||
sfree(msgboxtext);
|
||||
sfree(errmsg);
|
||||
} else {
|
||||
need_size = TRUE;
|
||||
@ -3228,6 +3231,7 @@ void fork_and_exec_self(struct gui_data *inst, int fd_to_close, ...)
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
sfree(args);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -3261,6 +3265,7 @@ void fork_and_exec_self(struct gui_data *inst, int fd_to_close, ...)
|
||||
|
||||
} else {
|
||||
int status;
|
||||
sfree(args);
|
||||
waitpid(pid, &status, 0);
|
||||
}
|
||||
|
||||
@ -3339,6 +3344,7 @@ int read_dupsession_data(struct gui_data *inst, Conf *conf, char *arg)
|
||||
}
|
||||
|
||||
size_used = conf_deserialise(conf, data, size);
|
||||
sfree(data);
|
||||
if (use_pty_argv && size > size_used) {
|
||||
int n = 0;
|
||||
i = size_used;
|
||||
|
@ -26,6 +26,7 @@ char *get_random_data(int len)
|
||||
ret = read(fd, buf+ngot, len-ngot);
|
||||
if (ret < 0) {
|
||||
close(fd);
|
||||
sfree(buf);
|
||||
perror("puttygen: unable to read /dev/random");
|
||||
return NULL;
|
||||
}
|
||||
|
@ -297,6 +297,7 @@ Socket platform_new_connection(SockAddr addr, char *hostname,
|
||||
|
||||
if (pid < 0) {
|
||||
ret->error = dupprintf("fork: %s", strerror(errno));
|
||||
sfree(cmd);
|
||||
return (Socket)ret;
|
||||
} else if (pid == 0) {
|
||||
close(0);
|
||||
|
@ -308,6 +308,7 @@ static const char *serial_init(void *frontend_handle, void **backend_handle,
|
||||
{
|
||||
char *msg = dupprintf("Opening serial device %s", line);
|
||||
logevent(serial->frontend, msg);
|
||||
sfree(msg);
|
||||
}
|
||||
|
||||
serial->fd = open(line, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
|
||||
|
@ -565,6 +565,7 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
|
||||
ret = ssh_sftp_do_select(TRUE, no_fds_ok);
|
||||
if (ret < 0) {
|
||||
printf("connection died\n");
|
||||
sfree(buf);
|
||||
return NULL; /* woop woop */
|
||||
}
|
||||
if (ret > 0) {
|
||||
@ -575,10 +576,12 @@ char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
|
||||
ret = read(0, buf+buflen, 1);
|
||||
if (ret < 0) {
|
||||
perror("read");
|
||||
sfree(buf);
|
||||
return NULL;
|
||||
}
|
||||
if (ret == 0) {
|
||||
/* eof on stdin; no error, but no answer either */
|
||||
sfree(buf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -299,8 +299,10 @@ void *open_settings_r(const char *sessionname)
|
||||
char *value = strchr(line, '=');
|
||||
struct skeyval *kv;
|
||||
|
||||
if (!value)
|
||||
if (!value) {
|
||||
sfree(line);
|
||||
continue;
|
||||
}
|
||||
*value++ = '\0';
|
||||
value[strcspn(value, "\r\n")] = '\0'; /* trim trailing NL */
|
||||
|
||||
@ -589,9 +591,6 @@ void store_host_key(const char *hostname, int port,
|
||||
int headerlen;
|
||||
char *filename, *tmpfilename;
|
||||
|
||||
newtext = dupprintf("%s@%d:%s %s\n", keytype, port, hostname, key);
|
||||
headerlen = 1 + strcspn(newtext, " "); /* count the space too */
|
||||
|
||||
/*
|
||||
* Open both the old file and a new file.
|
||||
*/
|
||||
@ -613,6 +612,9 @@ void store_host_key(const char *hostname, int port,
|
||||
filename = make_filename(INDEX_HOSTKEYS, NULL);
|
||||
rfp = fopen(filename, "r");
|
||||
|
||||
newtext = dupprintf("%s@%d:%s %s\n", keytype, port, hostname, key);
|
||||
headerlen = 1 + strcspn(newtext, " "); /* count the space too */
|
||||
|
||||
/*
|
||||
* Copy all lines from the old file to the new one that _don't_
|
||||
* involve the same host key identifier as the one we're adding.
|
||||
@ -621,6 +623,7 @@ void store_host_key(const char *hostname, int port,
|
||||
while ( (line = fgetline(rfp)) ) {
|
||||
if (strncmp(line, newtext, headerlen))
|
||||
fputs(line, wfp);
|
||||
sfree(line);
|
||||
}
|
||||
fclose(rfp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user