Skip to content

Commit 887dca2

Browse files
committed
optimize heap allocation in nanorq_generate_symbols
1 parent 6ea9ac5 commit 887dca2

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/nanorq.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,19 +472,20 @@ bool nanorq_generate_symbols(nanorq *rq, uint8_t sbn, struct ioctx *io) {
472472
}
473473
}
474474

475+
uint8_t *tmp_buf = (uint8_t *)malloc(rq->common.T);
476+
if (!tmp_buf)
477+
return false;
478+
475479
for (int esi = 0; esi < enc->K; esi++) {
476-
uint8_t *tmp_buf = (uint8_t *)malloc(rq->common.T);
477-
if (!tmp_buf)
478-
return false;
479480
size_t got =
480481
transfer_esi(rq, sbn, esi, enc->K, tmp_buf, rq->common.T, io, 0);
481482
if (got < rq->common.T) {
482483
memset(tmp_buf + got, 0, rq->common.T - got);
483484
}
484485
nanorq_core_place_symbol(&enc->core, enc->D, enc->stride, esi, tmp_buf,
485486
rq->common.T);
486-
free(tmp_buf);
487487
}
488+
free(tmp_buf);
488489
enc->loaded = true;
489490
}
490491

0 commit comments

Comments
 (0)