#include<peer.h>
static int peer_piece_request_init(struct piece_request**);
+static void peer_piece_request_free(struct piece_request*);
int peer_request(struct peer *info) {
return -1;
}
-int peer_piece_request_init(struct piece_request **p) {
+static void peer_piece_request_free(struct piece_request *p) {
+ free(p);
+}
+
+static int peer_piece_request_init(struct piece_request **p) {
if(NULL==p) { return -1; }
(*p) = malloc(sizeof(struct piece_request));
req->begin = BYTES_TO_UINT32_T((&(buf[9])));
req->length = BYTES_TO_UINT32_T((&(buf[13])));
- if(peer_piece_queue(info,req)<0) { return -1; }
+ if(req->length>16384) { goto clean; }
+
+ if(peer_piece_queue(info,req)<0) { goto clean; }
return 1;
+clean:
+ peer_piece_request_free(req);
+ return -1;
}