Skip to content

Commit ac13698

Browse files
committed
remove potential leaks
1 parent 6a3a0ab commit ac13698

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/forder.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,10 @@ static void range_str(const SEXP *x, int n, uint64_t *out_min, uint64_t *out_max
362362
}
363363
// now use the 1-1 mapping from ustr to ustr2 to get the ordering back into original ustr, being careful to reset tl to 0
364364
int *tl = (int *)malloc(ustr_n * sizeof(int));
365-
if (!tl)
365+
if (!tl) {
366+
free(ustr3);
366367
STOP(_("Failed to alloc tl when converting strings to UTF8")); // # nocov
368+
}
367369
const SEXP *tt = STRING_PTR_RO(ustr2);
368370
for (int i=0; i<ustr_n; i++) tl[i] = TRUELENGTH(tt[i]); // fetches the o in ustr3 into tl which is ordered by ustr
369371
for (int i=0; i<ustr_n; i++) SET_TRUELENGTH(ustr3[i], 0); // reset to 0 tl of the UTF8 (and possibly non-UTF in ustr too)
@@ -664,8 +666,10 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
664666
for (int b=0; b<nbyte; b++) {
665667
if (key[nradix+b]==NULL) {
666668
uint8_t *tt = calloc(nrow, sizeof(uint8_t)); // 0 initialize so that NA's can just skip (NA is always the 0 offset)
667-
if (!tt)
669+
if (!tt) {
670+
free(key);
668671
STOP(_("Unable to allocate %"PRIu64" bytes of working memory"), (uint64_t)nrow*sizeof(uint8_t)); // # nocov
672+
}
669673
key[nradix+b] = tt;
670674
}
671675
}

0 commit comments

Comments
 (0)