diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-03-11 16:30:32 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-03-11 16:30:32 +0100 |
commit | 44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6 (patch) | |
tree | 5d09284ebedfbe4b77a81edea2d0341fc2d230fa | |
parent | add included files to makefile (diff) | |
download | travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.tar travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.tar.gz travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.tar.bz2 travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.tar.lz travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.tar.xz travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.tar.zst travnik-44ada6ae69bc7e49d374bba8f682a6dfeaa07ef6.zip |
-rw-r--r-- | src/bencoding.c | 8 | ||||
-rw-r--r-- | src/dht.c | 10 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/bencoding.c b/src/bencoding.c index 6e8a2a2..991ac9c 100644 --- a/src/bencoding.c +++ b/src/bencoding.c @@ -453,13 +453,17 @@ struct bencoding * bdecode_safe (const char * s, int len, enum benc opts, unsign b->intvalue = strtol(s+1, &ch, 10); b->valuelen = ch-(s+1); b->value = malloc(b->valuelen+1); - if (!b->value) + if (!b->value) { + free(b); return NULL; + } strncpy(b->value, s+1, b->valuelen); b->value[b->valuelen] = '\0'; b->after = s+2+b->valuelen; - } else + } else { + free(b); return NULL; + } break; case 'd': /* dict */ b->type = dict; @@ -1330,10 +1330,10 @@ void oom (struct dht * d) { while (drop && (drop->type || drop->dl)) drop = drop->prev; struct torrent * old = drop; - remove_torrent(d, old); if (!drop) break; drop = drop->prev; + remove_torrent(d, old); } } @@ -2306,7 +2306,7 @@ void periodic (struct dht * d) { c = rand() % c; while (n && c--) n = n->next; - if (n && sent < 3) { // we pick some consecutive at random and ping them. + while (n && sent < 3) { // we pick some consecutive at random and ping them. sent++; // increase to more than this if desired ... idk this is shit if (!n->unanswered) n->last_sent = seconds(); @@ -2316,7 +2316,7 @@ void periodic (struct dht * d) { if (!n && !t->nodes->unanswered) // if unanswered, we already sent it n = t->nodes; } - if (sent < 2) { + while (sent < 2) { #define RTGP(buckets) {struct bucket * b = d->buckets; \ find(t->hash, &b, NULL); \ struct node * n = b->nodes; \ @@ -2335,7 +2335,7 @@ void periodic (struct dht * d) { RTGP(buckets); RTGP(buckets6); } - if (sent < 1) { + while (sent < 1) { struct bucket * b = d->buckets; while (sent < 1 && b) { n = b->nodes; @@ -2344,7 +2344,7 @@ void periodic (struct dht * d) { c = rand() % c; while (n && c--) n = n->next; - if (sent < 1 && n) { + while (sent < 1 && n) { sent++; if (!n->unanswered) n->last_sent = seconds(); |