Skip to content

Commit b7f2106

Browse files
Fix forder segfault (#6800)
* Cannot UNPROTECT recycleAscArg SEXP which livs on as ascArg * NEWS
1 parent 6922a91 commit b7f2106

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ rowwiseDT(
133133
134134
19. An integer overflow in `fread()` with lines longer than `2^(31/2)` bytes is prevented, [#6729](https://github.com/Rdatatable/data.table/issues/6729). The typical impact was no worse than a wrong initial allocation size, corrected later. Thanks to @TaikiSan21 for the report and @aitap for the fix.
135135
136+
20. Fixed a memory issue causing segfaults in `forder`, [#6797](https://github.com/Rdatatable/data.table/issues/6797). Thanks @dkutner for the report and @MichaelChirico for the fix.
137+
136138
## NOTES
137139
138140
1. There is a new vignette on joins! See `vignette("datatable-joins")`. Thanks to Angel Feliz for authoring it! Feedback welcome. This vignette has been highly requested since 2017: [#2181](https://github.com/Rdatatable/data.table/issues/2181).

src/forder.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,11 +488,10 @@ SEXP forder(SEXP DT, SEXP by, SEXP retGrpArg, SEXP retStatsArg, SEXP sortGroupsA
488488
if (LENGTH(ascArg) != LENGTH(by)) {
489489
if (LENGTH(ascArg)!=1)
490490
STOP(_("'order' length (%d) is different to by='s length (%d)"), LENGTH(ascArg), LENGTH(by));
491-
SEXP recycleAscArg = PROTECT(allocVector(INTSXP, LENGTH(by)));
491+
SEXP recycleAscArg = PROTECT(allocVector(INTSXP, LENGTH(by))); n_protect++;
492492
for (int j=0; j<LENGTH(recycleAscArg); j++)
493493
INTEGER(recycleAscArg)[j] = INTEGER(ascArg)[0];
494494
ascArg = recycleAscArg;
495-
UNPROTECT(1); // recycleAscArg
496495
}
497496
nrow = length(VECTOR_ELT(DT,0));
498497
int n_cplx = 0;

0 commit comments

Comments
 (0)