fix: file handle leak in cmd_sendfile on OMEMO error (upstream 156b78ad)

This commit is contained in:
2026-03-31 19:09:16 +03:00
parent 7f7e8307f4
commit 1c95446084

View File

@@ -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 {