Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ambrop72/badvpn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/flow
diff options
context:
space:
mode:
authorambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140>2011-03-13 15:42:42 +0300
committerambrop7 <ambrop7@1a93d707-3861-5ebc-ad3b-9740d49b5140>2011-03-13 15:42:42 +0300
commit6f95696566235d6fb2eac1b2e384bfb1203fa53d (patch)
treed1209e53c6bbf582dc0369e8d591551992734a25 /flow
parent600ee272bf331271575954d64ba2a55bdf46aa50 (diff)
ChunkBuffer2: add ChunkBuffer2_calc_blocks for computing the number of blocks, checking for overflows
Diffstat (limited to 'flow')
-rw-r--r--flow/PacketBuffer.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/flow/PacketBuffer.c b/flow/PacketBuffer.c
index e782734..246c321 100644
--- a/flow/PacketBuffer.c
+++ b/flow/PacketBuffer.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <misc/debug.h>
+#include <misc/balloc.h>
#include <flow/PacketBuffer.h>
@@ -92,8 +93,11 @@ int PacketBuffer_Init (PacketBuffer *buf, PacketRecvInterface *input, PacketPass
PacketPassInterface_Sender_Init(buf->output, (PacketPassInterface_handler_done)output_handler_done, buf);
// allocate buffer
- int num_blocks = CHUNKBUFFER2_MAKE_NUMBLOCKS(buf->input_mtu, num_packets);
- if (!(buf->buf_data = malloc(num_blocks * sizeof(struct ChunkBuffer2_block)))) {
+ int num_blocks = ChunkBuffer2_calc_blocks(buf->input_mtu, num_packets);
+ if (num_blocks < 0) {
+ goto fail0;
+ }
+ if (!(buf->buf_data = BAllocArray(num_blocks, sizeof(struct ChunkBuffer2_block)))) {
goto fail0;
}
@@ -116,5 +120,5 @@ void PacketBuffer_Free (PacketBuffer *buf)
DebugObject_Free(&buf->d_obj);
// free buffer
- free(buf->buf_data);
+ BFree(buf->buf_data);
}