diff options
author | Yunchih Chen <yunchih.cat@gmail.com> | 2017-12-06 00:12:20 +0800 |
---|---|---|
committer | Yunchih Chen <yunchih.cat@gmail.com> | 2017-12-06 00:12:20 +0800 |
commit | 0503266b60eb42a3714f0c29afec0b9f282558a9 (patch) | |
tree | fb270da62d097cfcacb487cd451e7ac9f7cda4b2 | |
parent | ec34224945af83be6244fb7c075b51a514806367 (diff) | |
download | nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.tar nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.tar.gz nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.tar.bz2 nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.tar.lz nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.tar.xz nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.tar.zst nfcollect-0503266b60eb42a3714f0c29afec0b9f282558a9.zip |
Fix double heap allocation
-rw-r--r-- | main.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -133,17 +133,20 @@ int main(int argc, char *argv[]) { sem_init(&nfl_commit_queue, 0, max_commit_worker); // Set up nflog receiver worker - nflog_state_t **trunks = (nflog_state_t **)malloc(sizeof(void*) * trunk_cnt); + nflog_state_t **trunks = (nflog_state_t **)calloc(trunk_cnt, sizeof(void*)); for (i = 0; i < trunk_cnt; ++i) { trunks[i] = NULL; } nfl_commit_init(trunk_cnt); + debug("Worker started, entries_max = %d, trunk_cnt = %d, trunk_size_byte = %d", + entries_max, trunk_cnt, trunk_size_byte); for (i = 0;; i = (i + 1) % trunk_cnt) { + if(trunks[i]) + pthread_mutex_lock(&(trunks[i]->lock)); nfl_state_update_or_create(&(trunks[i]), i, entries_max); // will be unlocked when #i has finished receiving & committing - pthread_mutex_lock(&(trunks[i]->lock)); pthread_create(&(trunks[i]->thread), NULL, nflog_worker, (void *)trunks[i]); // wait for current receiver worker |