Skip to content

Commit

Permalink
Avoid SET_TRUELENGTH, fix allocation bug
Browse files Browse the repository at this point in the history
We set the true length to the LENGTH, which was not
correct, it was a weird form of memory leak.
  • Loading branch information
gaborcsardi committed Apr 23, 2024
1 parent c157ff7 commit 19cedea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/read_lines.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ SEXP brio_read_lines(SEXP path, SEXP n) {
UNPROTECT(1);
}

if (out_num < Rf_xlength(out)) {
SETLENGTH(out, out_num);
SET_TRUELENGTH(out, out_num);
}
// Rf_xlengthgets is very cheap if the size is already correct, so
// don't check for size mismatch. It is very likely that there is a
// mismatch, anyway.
REPROTECT(out = Rf_lengthgets(out, out_num), out_idx);

fclose(fp);
free(line.data);
Expand Down

0 comments on commit 19cedea

Please sign in to comment.