curls?ftpsink: Fix memory leaks due to new error handling

Fixes https://bugzilla.gnome.org/show_bug.cgi?id=732174
This commit is contained in:
Sebastian Rasmussen 2014-06-24 16:32:22 +02:00 committed by Sebastian Dröge
parent 42b3d6ec8a
commit 96c78695f9
2 changed files with 14 additions and 19 deletions

View file

@ -185,7 +185,6 @@ set_ftp_dynamic_options_unlocked (GstCurlBaseSink * basesink)
gchar *rename_to = NULL; gchar *rename_to = NULL;
gchar *uploadfile_as = NULL; gchar *uploadfile_as = NULL;
gchar *last_slash = NULL; gchar *last_slash = NULL;
gchar *dir_name = NULL;
gchar *tmpfile_name = NULL; gchar *tmpfile_name = NULL;
if (sink->headerlist != NULL) { if (sink->headerlist != NULL) {
@ -204,57 +203,54 @@ set_ftp_dynamic_options_unlocked (GstCurlBaseSink * basesink)
last_slash = strrchr (basesink->file_name, '/'); last_slash = strrchr (basesink->file_name, '/');
if (last_slash != NULL) { if (last_slash != NULL) {
dir_name = gchar *dir_name =
g_strndup (basesink->file_name, last_slash - basesink->file_name); g_strndup (basesink->file_name, last_slash - basesink->file_name);
rename_to = g_strdup_printf ("%s%s", RENAME_TO, last_slash + 1); rename_to = g_strdup_printf ("%s%s", RENAME_TO, last_slash + 1);
uploadfile_as = g_strdup_printf ("%s/%s", dir_name, tmpfile_name); uploadfile_as = g_strdup_printf ("%s/%s", dir_name, tmpfile_name);
g_free (dir_name);
} else { } else {
rename_to = g_strdup_printf ("%s%s", RENAME_TO, basesink->file_name); rename_to = g_strdup_printf ("%s%s", RENAME_TO, basesink->file_name);
uploadfile_as = g_strdup_printf ("%s", tmpfile_name); uploadfile_as = g_strdup_printf ("%s", tmpfile_name);
} }
g_free (tmpfile_name);
tmp = g_strdup_printf ("%s%s", basesink->url, uploadfile_as); tmp = g_strdup_printf ("%s%s", basesink->url, uploadfile_as);
g_free (uploadfile_as);
sink->headerlist = curl_slist_append (sink->headerlist, rename_from);
sink->headerlist = curl_slist_append (sink->headerlist, rename_to);
g_free (rename_from);
g_free (rename_to);
res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp); res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
g_free (tmp);
if (res != CURLE_OK) { if (res != CURLE_OK) {
g_free (tmp);
basesink->error = g_strdup_printf ("failed to set URL: %s", basesink->error = g_strdup_printf ("failed to set URL: %s",
curl_easy_strerror (res)); curl_easy_strerror (res));
return FALSE; return FALSE;
} }
sink->headerlist = curl_slist_append (sink->headerlist, rename_from);
sink->headerlist = curl_slist_append (sink->headerlist, rename_to);
res = curl_easy_setopt (basesink->curl, CURLOPT_POSTQUOTE, sink->headerlist); res = curl_easy_setopt (basesink->curl, CURLOPT_POSTQUOTE, sink->headerlist);
if (res != CURLE_OK) { if (res != CURLE_OK) {
g_free (tmp);
basesink->error = g_strdup_printf ("failed to set post quote: %s", basesink->error = g_strdup_printf ("failed to set post quote: %s",
curl_easy_strerror (res)); curl_easy_strerror (res));
return FALSE; return FALSE;
} }
g_free (rename_from);
g_free (rename_to);
g_free (uploadfile_as);
g_free (dir_name);
g_free (tmpfile_name);
if (last_slash != NULL) { if (last_slash != NULL) {
*last_slash = '\0'; *last_slash = '\0';
} }
} else { } else {
tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name); tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name);
res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp); res = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
g_free (tmp);
if (res != CURLE_OK) { if (res != CURLE_OK) {
g_free (tmp);
basesink->error = g_strdup_printf ("failed to set URL: %s", basesink->error = g_strdup_printf ("failed to set URL: %s",
curl_easy_strerror (res)); curl_easy_strerror (res));
return FALSE; return FALSE;
} }
} }
g_free (tmp);
return TRUE; return TRUE;
} }

View file

@ -140,15 +140,14 @@ set_sftp_dynamic_options_unlocked (GstCurlBaseSink * basesink)
gchar *tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name); gchar *tmp = g_strdup_printf ("%s%s", basesink->url, basesink->file_name);
CURLcode curl_err = CURLE_OK; CURLcode curl_err = CURLE_OK;
if ((curl_err = curl_err = curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp);
curl_easy_setopt (basesink->curl, CURLOPT_URL, tmp)) != CURLE_OK) { g_free (tmp);
if (curl_err != CURLE_OK) {
basesink->error = g_strdup_printf ("failed to set URL: %s", basesink->error = g_strdup_printf ("failed to set URL: %s",
curl_easy_strerror (curl_err)); curl_easy_strerror (curl_err));
return FALSE; return FALSE;
} }
g_free (tmp);
return TRUE; return TRUE;
} }