diff options
| author | Richard Nyberg <rnyberg@murmeldjur.se> | 2009-02-03 23:11:34 +0100 |
|---|---|---|
| committer | Richard Nyberg <rnyberg@murmeldjur.se> | 2009-02-03 23:28:48 +0100 |
| commit | 432be0a10329c3209610a3af932209819b5999b5 (patch) | |
| tree | 7f6cfc9e38a5fc262db3c155aab702062bf1f581 | |
| parent | 74feed32d6ebb4c479d2635f9804de9dc06bdcd0 (diff) | |
| download | btpd-432be0a10329c3209610a3af932209819b5999b5.tar.gz btpd-432be0a10329c3209610a3af932209819b5999b5.zip | |
Make net->piece_count properly aligned.
The misalignment caused btpd to not work properly on machines like the NSLU2. Reported by John Caldwell.
| -rw-r--r-- | btpd/net.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/btpd/net.c b/btpd/net.c index 85739b3..3e76cb7 100644 --- a/btpd/net.c +++ b/btpd/net.c @@ -41,23 +41,21 @@ net_torrent_has_peer(struct net *n, const uint8_t *id) void net_create(struct torrent *tp) { - size_t field_size = ceil(tp->npieces / 8.0); - size_t mem = sizeof(*(tp->net)) + field_size + - tp->npieces * sizeof(*(tp->net->piece_count)); - - struct net *n = btpd_calloc(1, mem); + struct net *n = btpd_calloc(1, sizeof(*n)); n->tp = tp; tp->net = n; BTPDQ_INIT(&n->getlst); - - n->busy_field = (uint8_t *)(n + 1); - n->piece_count = (unsigned *)(n->busy_field + field_size); + + n->busy_field = btpd_calloc(ceil(tp->npieces / 8.0), 1); + n->piece_count = btpd_calloc(tp->npieces, sizeof(*n->piece_count)); } void net_kill(struct torrent *tp) { + free(tp->net->piece_count); + free(tp->net->busy_field); free(tp->net); tp->net = NULL; } |