KGIII / pino-twitter

Automatically exported from code.google.com/p/pino-twitter
GNU Lesser General Public License v3.0
0 stars 0 forks source link

crash due to misuse of libsoup #243

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
qv https://bugzilla.gnome.org/show_bug.cgi?id=617182

In both main_window.vala and rest_api_abstract.vala, you do something like:

    MessageHeaders headers = new 
MessageHeaders(MessageHeadersType.MULTIPART);
    headers.append("Authorization", h);
    message.request_headers = headers;

which is wrong and will eventually cause crashes (because both vala and 
libsoup will free message.request_headers). You want to replace those three 
lines with just:

    message.request_headers.append("Authorization", h);

(and likewise in rest_api_abstract.vala)

other issues:

You can also remove

    message.set_http_version (HTTPVersion.1_1);

from both files, since that's the default, and is documented as such.

In a few places you have "(string)message.response_body.flatten().data". 
The "flatten()" should be unnecessary there. Just doing 
"(string)message.response_body.data" should be equivalent. (Note that it 
currently leaks memory, since you need to free the return value of 
flatten().)

In rest_api_abstract.vala, you can replace all the params handling by just 
using Soup.form_request_new() instead of new Soup.Message(). 
(soup_form_request_new() will complain if the method isn't GET or POST, so 
you'd still have to use new Soup.Message if the method was DELETE. But 
there are never any params in that case, so you can still get rid of the 
params-handling code).

The fact that you create a new session for each call to make_request() 
means that it can never reuse HTTP connections between requests. I don't 
know how much of an issue that is for you (ie, how many requests you make, 
and how frequently).

Finally, note that calling soup_session_send_message() in 
rest_api_abstract.vala and oauth-client.vala means you're starting an inner 
GMainLoop, which can potentially cause problems (eg, idles/timeouts/event 
handlers may run from inside the inner main loop before the send_message() 
call returns). There is no easy way to change this, but that doesn't mean 
it's not going to cause problems later. The fix would be to either do all 
the HTTP stuff synchronously in a separate thread from the UI, or else make 
make_request() be an asynchronous method, and change everything else to 
deal with that.

Original issue reported on code.google.com by dan.wins...@gmail.com on 3 May 2010 at 6:48

GoogleCodeExporter commented 8 years ago
Closed by 87e130c116 revision. Thanks a lot.

Original comment by tro...@gmail.com on 4 May 2010 at 7:03