Skip to content

Commit ff3822d

Browse files
committed
NetFlow9 converter: avoid too many reallocations
1 parent 40be195 commit ff3822d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/core/netflow2ipfix/netflow9.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,12 @@ conv_mem_reserve(ipx_nf9_conv_t *conv, size_t size)
297297
return IPX_OK;
298298
}
299299

300-
// Reallocate // TODO: improve size - multiples of 1024? 1024, 2048, 4096, ...
301-
size_t new_alloc = conv->data.ipx_size_used + size; // TODO: during TEST allocate only to required size and use valgrind
300+
// Reallocate - use multiples of 1024 to avoid too many reallocations
301+
size_t new_alloc = conv->data.ipx_size_used + size;
302+
new_alloc /= 1024U;
303+
new_alloc += 1U;
304+
new_alloc *= 1024U;
305+
// TODO: during TEST allocate only to required size and use valgrind
302306
uint8_t *new_msg = realloc(conv->data.ipx_msg, new_alloc * sizeof(uint8_t));
303307
if (!new_msg) {
304308
return IPX_ERR_NOMEM;

0 commit comments

Comments
 (0)