send_request: don't leak the curl stuff
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>
Tue, 19 Jul 2011 14:06:58 +0000 (16:06 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Sat, 22 Oct 2011 16:11:59 +0000 (18:11 +0200)
This is a bit ugly, admittedly.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
bti.c

diff --git a/bti.c b/bti.c
index 6f77ddc..9a6fae2 100644 (file)
--- a/bti.c
+++ b/bti.c
@@ -557,8 +557,10 @@ static int send_request(struct session *session)
                curl_buf->session = session;
 
                curl = curl_init();
-               if (!curl)
+               if (!curl) {
+                       bti_curl_buffer_free(curl_buf);
                        return -EINVAL;
+               }
 
                if (!session->hosturl)
                        session->hosturl = strdup(twitter_host);
@@ -658,6 +660,10 @@ static int send_request(struct session *session)
                                if (res) {
                                        fprintf(stderr, "error(%d) trying to "
                                                "perform operation\n", res);
+                                       curl_easy_cleanup(curl);
+                                       if (session->action == ACTION_UPDATE)
+                                               curl_formfree(formpost);
+                                       bti_curl_buffer_free(curl_buf);
                                        return -EINVAL;
                                }
 
@@ -665,19 +671,32 @@ static int send_request(struct session *session)
                                                    curl_buf->length,
                                                    "response.xml", NULL,
                                                    XML_PARSE_NOERROR);
-                               if (doc == NULL)
+                               if (doc == NULL) {
+                                       curl_easy_cleanup(curl);
+                                       if (session->action == ACTION_UPDATE)
+                                               curl_formfree(formpost);
+                                       bti_curl_buffer_free(curl_buf);
                                        return -EINVAL;
+                               }
 
                                current = xmlDocGetRootElement(doc);
                                if (current == NULL) {
                                        fprintf(stderr, "empty document\n");
                                        xmlFreeDoc(doc);
+                                       curl_easy_cleanup(curl);
+                                       if (session->action == ACTION_UPDATE)
+                                               curl_formfree(formpost);
+                                       bti_curl_buffer_free(curl_buf);
                                        return -EINVAL;
                                }
 
                                if (xmlStrcmp(current->name, (const xmlChar *)"status")) {
                                        fprintf(stderr, "unexpected document type\n");
                                        xmlFreeDoc(doc);
+                                       curl_easy_cleanup(curl);
+                                       if (session->action == ACTION_UPDATE)
+                                               curl_formfree(formpost);
+                                       bti_curl_buffer_free(curl_buf);
                                        return -EINVAL;
                                }