Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Commit

Permalink
Add an assortment of missing frees and closes.
Browse files Browse the repository at this point in the history
Coverity's resource-leak checker is on the ball as usual.
  • Loading branch information
sgtatham committed Feb 14, 2017
1 parent 33f4c83 commit 12a0808
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmdgen.c
Expand Up @@ -1162,6 +1162,8 @@ void test(int retval, ...)
} else {
passes++;
}

sfree(argv);
}

void filecmp(char *file1, char *file2, char *fmt, ...)
Expand Down
22 changes: 22 additions & 0 deletions pageant.c
Expand Up @@ -406,6 +406,7 @@ void *pageant_handle_msg(const void *msg, int msglen, int *outlen,
if (i < 0) {
freebn(reqkey.exponent);
freebn(reqkey.modulus);
freebn(challenge);
fail_reason = "request truncated before challenge";
goto failure;
}
Expand Down Expand Up @@ -1334,6 +1335,8 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
int n = rsa_public_blob_len(p, keylistlen);
if (n < 0) {
*retstr = dupstr("Received broken key list from agent");
sfree(keylist);
sfree(blob);
return PAGEANT_ACTION_FAILURE;
}
p += n;
Expand All @@ -1342,6 +1345,8 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
int n;
if (keylistlen < 4) {
*retstr = dupstr("Received broken key list from agent");
sfree(keylist);
sfree(blob);
return PAGEANT_ACTION_FAILURE;
}
n = GET_32BIT(p);
Expand All @@ -1350,6 +1355,8 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,

if (n < 0 || n > keylistlen) {
*retstr = dupstr("Received broken key list from agent");
sfree(keylist);
sfree(blob);
return PAGEANT_ACTION_FAILURE;
}
p += n;
Expand All @@ -1360,6 +1367,8 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
int n;
if (keylistlen < 4) {
*retstr = dupstr("Received broken key list from agent");
sfree(keylist);
sfree(blob);
return PAGEANT_ACTION_FAILURE;
}
n = GET_32BIT(p);
Expand All @@ -1368,6 +1377,8 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,

if (n < 0 || n > keylistlen) {
*retstr = dupstr("Received broken key list from agent");
sfree(keylist);
sfree(blob);
return PAGEANT_ACTION_FAILURE;
}
p += n;
Expand Down Expand Up @@ -1414,6 +1425,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
* Run out of passphrases to try.
*/
*retstr = comment;
sfree(rkey);
return PAGEANT_ACTION_NEED_PP;
}
} else
Expand All @@ -1437,6 +1449,7 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
* a bad passphrase.
*/
*retstr = dupstr(error);
sfree(rkey);
return PAGEANT_ACTION_FAILURE;
} else if (ret == 1) {
/*
Expand Down Expand Up @@ -1514,12 +1527,19 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS) {
*retstr = dupstr("The already running Pageant "
"refused to add the key.");
freersakey(rkey);
sfree(rkey);
sfree(request);
sfree(response);
return PAGEANT_ACTION_FAILURE;
}
freersakey(rkey);
sfree(rkey);
sfree(request);
sfree(response);
} else {
if (!pageant_add_ssh1_key(rkey)) {
freersakey(rkey);
sfree(rkey); /* already present, don't waste RAM */
}
}
Expand Down Expand Up @@ -1560,6 +1580,8 @@ int pageant_add_keyfile(Filename *filename, const char *passphrase,
if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS) {
*retstr = dupstr("The already running Pageant "
"refused to add the key.");
sfree(request);
sfree(response);
return PAGEANT_ACTION_FAILURE;
}

Expand Down
1 change: 1 addition & 0 deletions pscp.c
Expand Up @@ -383,6 +383,7 @@ static void do_cmd(char *host, char *user, char *cmd)
/* Use `host' as a bare hostname. */
conf_set_str(conf, CONF_host, host);
}
conf_free(conf2);
} else {
/* Patch in hostname `host' to session details. */
conf_set_str(conf, CONF_host, host);
Expand Down
1 change: 1 addition & 0 deletions ssh.c
Expand Up @@ -3954,6 +3954,7 @@ static void ssh_agentf_try_forward(struct ssh_channel *c)
* straight on and go round this loop again.
*/
ssh_agentf_got_response(c, reply, replylen);
sfree(reply);
}

/*
Expand Down
1 change: 1 addition & 0 deletions sshpubk.c
Expand Up @@ -946,6 +946,7 @@ unsigned char *rfc4716_loadpub(FILE *fp, char **algorithm,
}

*q = '\0';
sfree(comment); /* *just* in case of multiple Comment headers */
comment = dupstr(line);
} else if (!strcmp(line, "Subject") ||
!strncmp(line, "x-", 2)) {
Expand Down
1 change: 1 addition & 0 deletions unix/gtkdlg.c
Expand Up @@ -3304,6 +3304,7 @@ int do_config_box(const char *title, Conf *conf, int midsession,

dlg_cleanup(&dp);
sfree(selparams);
ctrl_free_box(ctrlbox);

return dp.retval;
}
Expand Down
1 change: 1 addition & 0 deletions unix/gtkfont.c
Expand Up @@ -1126,6 +1126,7 @@ static void x11font_enum_fonts(GtkWidget *widget,
}
}
XFreeFontNames(fontnames);
sfree(tmp);
}

static char *x11font_canonify_fontname(GtkWidget *widget, const char *name,
Expand Down
2 changes: 2 additions & 0 deletions unix/uxpgnt.c
Expand Up @@ -978,6 +978,8 @@ void run_agent(void)
fprintf(stderr, "pageant: %s: %s\n", socketname, strerror(errno));
exit(1);
}

conf_free(conf);
}

int main(int argc, char **argv)
Expand Down
1 change: 1 addition & 0 deletions windows/winhelp.c
Expand Up @@ -58,6 +58,7 @@ void init_help(void)
HINSTANCE dllHH = load_system32_dll("hhctrl.ocx");
GET_WINDOWS_FUNCTION(dllHH, HtmlHelpA);
if (!p_HtmlHelpA) {
sfree(chm_path);
chm_path = NULL;
if (dllHH)
FreeLibrary(dllHH);
Expand Down
4 changes: 4 additions & 0 deletions windows/winproxy.c
Expand Up @@ -77,6 +77,10 @@ Socket platform_new_connection(SockAddr addr, const char *hostname,
Socket ret = new_error_socket
("Unable to create pipes for proxy command", plug);
sfree(cmd);
CloseHandle(us_from_cmd);
CloseHandle(cmd_to_us);
CloseHandle(us_to_cmd);
CloseHandle(cmd_from_us);
return ret;
}
}
Expand Down
1 change: 1 addition & 0 deletions windows/winser.c
Expand Up @@ -220,6 +220,7 @@ static const char *serial_init(void *frontend_handle, void **backend_handle,
{
char *msg = dupprintf("Opening serial device %s", serline);
logevent(serial->frontend, msg);
sfree(msg);
}

{
Expand Down

0 comments on commit 12a0808

Please sign in to comment.