torrentd

simple torrent daemon
git clone git://git.2f30.org/torrentd
Log | Files | Refs | LICENSE

commit 0747827b3067eea950b8feaece8658b318d6d784
parent c718ff52b3ac436c40f6519848bb86a1f5d7dd97
Author: sin <sin@2f30.org>
Date:   Sat, 26 Dec 2015 16:30:03 +0000

cleanup

Diffstat:
Mtracker.c | 40+++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/tracker.c b/tracker.c @@ -103,14 +103,13 @@ getpeers(struct torrent *t) return -1; if (!(infohash = curl_easy_escape(curl, (char *)t->infohash, 20))) { - curl_easy_cleanup(curl); - return -1; + r = -1; + goto err0; } if (!(id = curl_easy_escape(curl, peerid(), 20))) { - curl_free(infohash); - curl_easy_cleanup(curl); - return -1; + r = -1; + goto err1; } r = snprintf(buf, sizeof(buf), @@ -118,29 +117,32 @@ getpeers(struct torrent *t) "downloaded=0&left=%zu&compact=1&event=started", t->announcers[0].urls[0], infohash, id, t->totallen); if (r < 0 || (size_t)r >= sizeof(buf)) { - curl_free(infohash); - curl_free(id); - curl_easy_cleanup(curl); - return -1; + r = -1; + goto err2; } initbuf(&reply); curl_easy_setopt(curl, CURLOPT_URL, buf); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefn); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &reply); - if ((res = curl_easy_perform(curl)) == CURLE_OK) { - if (parsepeers(t, &reply) < 0) { - curl_free(infohash); - curl_free(id); - curl_easy_cleanup(curl); - freebuf(&reply); - return -1; - } + if ((res = curl_easy_perform(curl)) != CURLE_OK) { + r = - 1; + goto err3; } - curl_free(infohash); + if (parsepeers(t, &reply) < 0) { + r = - 1; + goto err3; + } + + r = 0; +err3: + freebuf(&reply); +err2: curl_free(id); +err1: + curl_free(infohash); +err0: curl_easy_cleanup(curl); - freebuf(&reply); return r; }