libeech

BitTorrent library
git clone git://z3bra.org/libeech.git
Log | Files | Refs | README | LICENSE

commit fe9bdcbb5f33ca30a4e78fd4bbd4942f846049b9
parent e399823985f0dc7169562860c68296139e259d87
Author: z3bra <contactatz3bradotorg>
Date:   Fri Jun 29 23:06:12 +0200

Remove some more malloc()

Diffstat:
libeech.c | 9+++------
libeech.h | 8++++----
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/libeech.c b/libeech.c @@ -228,7 +228,8 @@ static long readpiece(struct torrent *t, struct piece *p, long n) { int i; - size_t off, fp, sz; + size_t off, fp; + ssize_t sz; FILE *fh = NULL; /* last piece might be truncated, so recalculate it*/ @@ -592,17 +593,13 @@ glch_loadtorrent(struct torrent *t, char *b, size_t s) /* pieces related values */ t->psz = bekint(&t->info, "piece length", 12); t->npiece = t->sz / t->psz + !!(t->sz % t->psz); - t->ph = malloc(t->npiece * 20); bekstr(&t->info, "pieces", 6, &v); memcpy(t->ph, v.off, v.end - v.off); - t->bf = malloc(t->npiece / 8 + 1); memset(t->bf, 0, t->npiece / 8 + 1); for (i = 0; i < t->npiece; i++) { - if (readpiece(t, &piece, i) > 0 && !chkpiece(t, &piece, i)) { - printf("PIECE %ld/%ld\n", i + 1, t->npiece); + if (readpiece(t, &piece, i) > 0 && !chkpiece(t, &piece, i)) setbit(t->bf, i); - } } return 1; diff --git a/libeech.h b/libeech.h @@ -22,7 +22,7 @@ enum { struct piece { int n; - size_t sz; + ssize_t sz; char blks[PCESIZ]; char bf[PCESIZ / BLKSIZ]; }; @@ -35,7 +35,7 @@ struct peer { char rxbuf[MSGSIZ]; long rxbufsz; char bf[PCENUM / 8]; - struct piece *piece; + struct piece piece; struct peer *next; }; @@ -48,8 +48,8 @@ struct torrent { char id[21]; char ih[20]; char tr[PATH_MAX]; - char *ph; - char *bf; + char bf[PCENUM]; + char ph[PCENUM]; struct be be; struct be info; struct peer *peers;