diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2023-01-29 15:24:15 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2023-01-29 15:24:15 +0100 |
commit | 7215e481030ceee395e517e4e195aeba3d467fd7 (patch) | |
tree | 4d917cb56e391a8a8ab75a64cbabf10e1d413d6e /src/main.c | |
parent | small tweaks introduced memory corruption. see misc/valgrind-2023-01-12.txt (diff) | |
download | travnik-7215e481030ceee395e517e4e195aeba3d467fd7.tar travnik-7215e481030ceee395e517e4e195aeba3d467fd7.tar.gz travnik-7215e481030ceee395e517e4e195aeba3d467fd7.tar.bz2 travnik-7215e481030ceee395e517e4e195aeba3d467fd7.tar.lz travnik-7215e481030ceee395e517e4e195aeba3d467fd7.tar.xz travnik-7215e481030ceee395e517e4e195aeba3d467fd7.tar.zst travnik-7215e481030ceee395e517e4e195aeba3d467fd7.zip |
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -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) |