mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 18:36:21 +00:00
fix: file handle leak in cmd_sendfile on OMEMO error (upstream 156b78ad)
This commit is contained in:
@@ -4963,6 +4963,11 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
||||
}
|
||||
|
||||
FILE* fh = fdopen(fd, "rb");
|
||||
if (!fh) {
|
||||
cons_show_error("Unable to open file descriptor for '%s'.", filename);
|
||||
close(fd);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (omemo_enabled) {
|
||||
#ifdef HAVE_OMEMO
|
||||
@@ -4972,12 +4977,23 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
||||
if (err != NULL) {
|
||||
cons_show_error("%s", err);
|
||||
win_println(window, THEME_ERROR, "-", "%s", err);
|
||||
if (fh) {
|
||||
fclose(fh);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
HTTPUpload* upload = malloc(sizeof(HTTPUpload));
|
||||
if (!upload) {
|
||||
cons_show_error("Memory allocation failed.");
|
||||
if (fh) {
|
||||
fclose(fh);
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
upload->window = window;
|
||||
|
||||
upload->filename = strdup(filename);
|
||||
@@ -4985,6 +5001,17 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
||||
upload->filesize = file_size(fd);
|
||||
upload->mime_type = file_mime_type(filename);
|
||||
|
||||
if (!upload->filename || !upload->mime_type) {
|
||||
cons_show_error("Memory allocation failed.");
|
||||
if (fh) {
|
||||
fclose(fh);
|
||||
}
|
||||
free(upload->filename);
|
||||
free(upload->mime_type);
|
||||
free(upload);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (alt_scheme != NULL) {
|
||||
upload->alt_scheme = strdup(alt_scheme);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user