summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 4368e21..b42c873 100644
--- a/src/main.c
+++ b/src/main.c
@@ -66,6 +66,8 @@ int main (int argc, char ** argv) {
struct pollfd * pollfds = NULL;
int r = 0;
struct dht * dht = NULL;
+ char * cfr = NULL;
+ struct bencoding * config = NULL;
struct sigaction sigact = {
.sa_handler = handler,
.sa_flags = SA_RESTART
@@ -110,15 +112,15 @@ int main (int argc, char ** argv) {
r = 12;
goto r;
}
- char * cfr = NULL;
if (statbuf.st_size && !(cfr = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, cf, 0))) {
error_at_line(0, errno, __FILE__, __LINE__, "mmap(NULL, %ld, PROT_READ, MAP_SHARED, cf, 0)", statbuf.st_size);
r = 13;
goto r;
}
- struct bencoding * config = bdecode(cfr, statbuf.st_size, replace);
+ config = bdecode(cfr, statbuf.st_size, replace);
dht = dht_init(config);
free_bencoding(config);
+ config = NULL;
dht->possible_torrent = found_torrent;
dht->connection = connection;
pollfds = malloc(sizeof *pollfds);
@@ -197,13 +199,15 @@ w:
goto r;
}
bencode(cfr, config);
- free_bencoding(config);
- config = NULL;
r:
if (dht) {
dht_free(dht);
dht = NULL;
}
+ if (config) {
+ free_bencoding(config);
+ config = NULL;
+ }
if (cfr && munmap(cfr, statbuf.st_size) == -1)
error_at_line(0, errno, __FILE__, __LINE__, "munmap(cf, %ld)", statbuf.st_size);
if (close(cf) == -1)