Skip to content

Commit

Permalink
booru/imagefetcher: Assign new SockInfo after setting up event callback
Browse files Browse the repository at this point in the history
This caused a rare issue were files would never get downloaded.
It was very  easy to trigger when downloading multiple files
at the same time either when the cache size is set to something
greater than zero or when saving images.
  • Loading branch information
ahodesuka committed Nov 25, 2017
1 parent 139b743 commit 7a24b8e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/booru/imagefetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ int ImageFetcher::socket_cb(CURL*, curl_socket_t s, int action, void *userp, voi
ImageFetcher *self = static_cast<ImageFetcher*>(userp);
SockInfo *fdp = static_cast<SockInfo*>(sockp);

if (action == CURL_POLL_REMOVE && fdp)
if (action == CURL_POLL_REMOVE)
{
delete fdp;
if (fdp)
delete fdp;
}
else
{
bool need_assign = false;

if (!fdp)
{
need_assign = true;
fdp = new SockInfo();
fdp->chan = Glib::IOChannel::create_from_fd(s);
curl_multi_assign(self->m_MultiHandle, s, fdp);
}

Glib::IOCondition kind;
Expand All @@ -31,6 +34,9 @@ int ImageFetcher::socket_cb(CURL*, curl_socket_t s, int action, void *userp, voi

fdp->conn = source->connect(sigc::bind<0>(sigc::mem_fun(self, &ImageFetcher::event_cb), s));
source->attach(self->m_MainContext);

if (need_assign)
curl_multi_assign(self->m_MultiHandle, s, fdp);
}

return 0;
Expand Down

0 comments on commit 7a24b8e

Please sign in to comment.