mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 21:16:22 +00:00
Slightly improve http_download related allocations.
* use `calloc()` to allocate zero-initialized structs. * order the allocation of members by their declaration. * order the freeing of members in reverse order. * move init of `silent` flag in plugin case. * fix double free of `tmpname` in `aesgcm_file_get()`. * make some functions static. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -9435,17 +9435,16 @@ _url_aesgcm_method(ProfWin* window, const char* cmd_template, gchar* url, gchar*
|
|||||||
auto_gchar gchar* filename = _prepare_filename(window, url, path);
|
auto_gchar gchar* filename = _prepare_filename(window, url, path);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return;
|
return;
|
||||||
auto_char char* id = get_random_string(4);
|
AESGCMDownload* download = calloc(1, sizeof(AESGCMDownload));
|
||||||
AESGCMDownload* download = malloc(sizeof(AESGCMDownload));
|
download->id = get_random_string(4);
|
||||||
download->window = window;
|
|
||||||
download->url = strdup(url);
|
download->url = strdup(url);
|
||||||
download->filename = strdup(filename);
|
download->filename = strdup(filename);
|
||||||
download->id = strdup(id);
|
|
||||||
if (cmd_template != NULL) {
|
if (cmd_template != NULL) {
|
||||||
download->cmd_template = strdup(cmd_template);
|
download->cmd_template = strdup(cmd_template);
|
||||||
} else {
|
} else {
|
||||||
download->cmd_template = NULL;
|
download->cmd_template = NULL;
|
||||||
}
|
}
|
||||||
|
download->window = window;
|
||||||
|
|
||||||
pthread_create(&(download->worker), NULL, &aesgcm_file_get, download);
|
pthread_create(&(download->worker), NULL, &aesgcm_file_get, download);
|
||||||
aesgcm_download_add_download(download);
|
aesgcm_download_add_download(download);
|
||||||
@@ -9458,38 +9457,38 @@ _download_install_plugin(ProfWin* window, gchar* url, gchar* path)
|
|||||||
auto_gchar gchar* filename = _prepare_filename(window, url, path);
|
auto_gchar gchar* filename = _prepare_filename(window, url, path);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
HTTPDownload* download = malloc(sizeof(HTTPDownload));
|
HTTPDownload* download = calloc(1, sizeof(HTTPDownload));
|
||||||
download->window = window;
|
download->id = get_random_string(4);
|
||||||
download->url = strdup(url);
|
download->url = strdup(url);
|
||||||
download->filename = strdup(filename);
|
download->filename = strdup(filename);
|
||||||
download->id = get_random_string(4);
|
|
||||||
download->cmd_template = NULL;
|
download->cmd_template = NULL;
|
||||||
|
download->window = window;
|
||||||
|
download->silent = TRUE;
|
||||||
|
|
||||||
pthread_create(&(download->worker), NULL, &plugin_download_install, download);
|
pthread_create(&(download->worker), NULL, &plugin_download_install, download);
|
||||||
plugin_download_add_download(download);
|
plugin_download_add_download(download);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
_url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* path)
|
_url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* path)
|
||||||
{
|
{
|
||||||
auto_gchar gchar* filename = _prepare_filename(window, url, path);
|
auto_gchar gchar* filename = _prepare_filename(window, url, path);
|
||||||
if (!filename)
|
if (!filename)
|
||||||
return;
|
return;
|
||||||
auto_char char* id = get_random_string(4);
|
HTTPDownload* download = calloc(1, sizeof(HTTPDownload));
|
||||||
HTTPDownload* download = malloc(sizeof(HTTPDownload));
|
download->id = get_random_string(4);
|
||||||
download->window = window;
|
|
||||||
download->url = strdup(url);
|
download->url = strdup(url);
|
||||||
download->filename = strdup(filename);
|
download->filename = strdup(filename);
|
||||||
download->id = strdup(id);
|
|
||||||
download->cmd_template = cmd_template ? strdup(cmd_template) : NULL;
|
download->cmd_template = cmd_template ? strdup(cmd_template) : NULL;
|
||||||
|
download->window = window;
|
||||||
download->silent = FALSE;
|
download->silent = FALSE;
|
||||||
|
|
||||||
pthread_create(&(download->worker), NULL, &http_file_get, download);
|
pthread_create(&(download->worker), NULL, &http_file_get, download);
|
||||||
http_download_add_download(download);
|
http_download_add_download(download);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
_url_external_method(const char* cmd_template, const char* url, gchar* filename)
|
_url_external_method(const char* cmd_template, const char* url, gchar* filename)
|
||||||
{
|
{
|
||||||
auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ aesgcm_file_get(void* userdata)
|
|||||||
|
|
||||||
// Create a temporary file used for storing the ciphertext that is to be
|
// Create a temporary file used for storing the ciphertext that is to be
|
||||||
// retrieved from the https:// URL.
|
// retrieved from the https:// URL.
|
||||||
auto_gchar char* tmpname = NULL;
|
auto_gchar gchar* tmpname = NULL;
|
||||||
auto_gfd gint tmpfd = 0;
|
auto_gfd gint tmpfd = 0;
|
||||||
if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
|
if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
@@ -101,7 +101,7 @@ aesgcm_file_get(void* userdata)
|
|||||||
|
|
||||||
// We wrap the HTTPDownload tool and use it for retrieving the ciphertext
|
// We wrap the HTTPDownload tool and use it for retrieving the ciphertext
|
||||||
// and storing it in the temporary file previously opened.
|
// and storing it in the temporary file previously opened.
|
||||||
HTTPDownload* http_dl = malloc(sizeof(HTTPDownload));
|
HTTPDownload* http_dl = calloc(1, sizeof(HTTPDownload));
|
||||||
http_dl->window = aesgcm_dl->window;
|
http_dl->window = aesgcm_dl->window;
|
||||||
http_dl->worker = aesgcm_dl->worker;
|
http_dl->worker = aesgcm_dl->worker;
|
||||||
http_dl->id = strdup(aesgcm_dl->id);
|
http_dl->id = strdup(aesgcm_dl->id);
|
||||||
@@ -128,7 +128,6 @@ aesgcm_file_get(void* userdata)
|
|||||||
http_dl->bytes_received, fragment);
|
http_dl->bytes_received, fragment);
|
||||||
|
|
||||||
remove(tmpname);
|
remove(tmpname);
|
||||||
g_free(tmpname);
|
|
||||||
|
|
||||||
if (crypt_res != GPG_ERR_NO_ERROR) {
|
if (crypt_res != GPG_ERR_NO_ERROR) {
|
||||||
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->id,
|
||||||
|
|||||||
@@ -236,9 +236,9 @@ out:
|
|||||||
download_processes = g_slist_remove(download_processes, download);
|
download_processes = g_slist_remove(download_processes, download);
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
|
|
||||||
free(download->id);
|
|
||||||
free(download->url);
|
|
||||||
free(download->filename);
|
free(download->filename);
|
||||||
|
free(download->url);
|
||||||
|
free(download->id);
|
||||||
free(download);
|
free(download);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ plugin_download_install(void* userdata)
|
|||||||
{
|
{
|
||||||
HTTPDownload* plugin_dl = (HTTPDownload*)userdata;
|
HTTPDownload* plugin_dl = (HTTPDownload*)userdata;
|
||||||
|
|
||||||
|
/* We need to dup those, because they're free'd inside `http_file_get()` */
|
||||||
auto_char char* path = strdup(plugin_dl->filename);
|
auto_char char* path = strdup(plugin_dl->filename);
|
||||||
auto_char char* https_url = strdup(plugin_dl->url);
|
auto_char char* https_url = strdup(plugin_dl->url);
|
||||||
plugin_dl->silent = TRUE;
|
|
||||||
|
|
||||||
http_file_get(plugin_dl);
|
http_file_get(plugin_dl);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user