Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #57 from b4n/fixes/geniuspaste

GeniusPaste: Fixes some memory leaks
  • Loading branch information...
commit b23f60dfeac76d878698a39c9f7870f9562aaac5 2 parents af1afff + 841d4c8
@frlan frlan authored
Showing with 14 additions and 16 deletions.
  1. +14 −16 geniuspaste/src/geniuspaste.c
View
30 geniuspaste/src/geniuspaste.c
@@ -183,7 +183,6 @@ static void paste(GeanyDocument * doc, const gchar * website)
gchar *p_url;
gchar *formdata = NULL;
gchar *user_agent = NULL;
- gchar *temp_body;
gchar **tokens_array;
const gchar *langs_supported_codepad[] =
@@ -297,16 +296,21 @@ static void paste(GeanyDocument * doc, const gchar * website)
}
+ g_free(f_content);
+
user_agent = g_strconcat(PLUGIN_NAME, " ", PLUGIN_VERSION, " / Geany ", GEANY_VERSION, NULL);
session = soup_session_async_new_with_options(SOUP_SESSION_USER_AGENT, user_agent, NULL);
g_free(user_agent);
soup_message_set_request(msg, "application/x-www-form-urlencoded",
- SOUP_MEMORY_COPY, formdata, strlen(formdata));
+ SOUP_MEMORY_TAKE, formdata, strlen(formdata));
status = soup_session_send_message(session, msg);
p_url = g_strdup(msg->response_body->data);
+ g_object_unref(session);
+ g_object_unref(msg);
+
if(status == SOUP_STATUS_OK)
{
@@ -317,17 +321,15 @@ static void paste(GeanyDocument * doc, const gchar * website)
if (website_selected == CODEPAD_ORG)
{
- temp_body = g_strdup(p_url);
- tokens_array = g_strsplit(temp_body, "<a href=\"", 0);
+ tokens_array = g_strsplit(p_url, "<a href=\"", 0);
/* cuts the string when it finds the first occurrence of '/'
* It shoud work even if codepad would change its url.
*/
- p_url = g_strdup(tokens_array[5]);
+ SETPTR(p_url, g_strdup(tokens_array[5]));
occ_position = indexof(tokens_array[5], '\"');
- g_free(temp_body);
g_strfreev(tokens_array);
if(occ_position != -1)
@@ -353,18 +355,16 @@ static void paste(GeanyDocument * doc, const gchar * website)
* <response>xxxxx</response>
* </result>
*/
- temp_body = g_strdup(p_url);
- tokens_array = g_strsplit_set(temp_body, "<>", 0);
+ tokens_array = g_strsplit_set(p_url, "<>", 0);
- p_url = g_strdup_printf("http://%s/%s", websites[TINYPASTE_COM], tokens_array[6]);
+ SETPTR(p_url, g_strdup_printf("http://%s/%s", websites[TINYPASTE_COM], tokens_array[6]));
- g_free(temp_body);
g_strfreev(tokens_array);
}
else if(website_selected == DPASTE_DE)
{
- p_url = g_strndup(p_url + 1, strlen(p_url) - 2);
+ SETPTR(p_url, g_strndup(p_url + 1, strlen(p_url) - 2));
}
else if(website_selected == SPRUNGE_US)
@@ -377,8 +377,8 @@ static void paste(GeanyDocument * doc, const gchar * website)
* e.g. sprunge.us/xxxx?c
*/
gchar *ft_tmp = g_ascii_strdown(f_type, -1);
- temp_body = g_strstrip(p_url);
- p_url = g_strdup_printf("%s?%s", temp_body, ft_tmp);
+ gchar *temp_body = g_strstrip(p_url);
+ SETPTR(p_url, g_strdup_printf("%s?%s", temp_body, ft_tmp));
g_free(temp_body);
g_free(ft_tmp);
}
@@ -405,9 +405,7 @@ static void paste(GeanyDocument * doc, const gchar * website)
"Error code: %d\n"), status);
}
- g_free(f_content);
g_free(p_url);
- g_object_unref(session);
}
static void item_activate(GtkMenuItem * menuitem, gpointer gdata)
@@ -435,7 +433,7 @@ static void on_configure_response(GtkDialog * dialog, gint response, gpointer *
{
website_selected = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets.combo));
check_button_is_checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets.check_button));
- author_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.author_entry)));
+ SETPTR(author_name, g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.author_entry))));
save_settings();
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.