Skip to content

Commit a7f5c6c

Browse files
committed
rbindlist: use hash_set_shared
Where C-heap allocations also exist, catch and handle potential allocation failures from the hash table.
1 parent a2b6926 commit a7f5c6c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/rbindlist.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,13 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
375375
for (int k=0; k<longestLen; ++k) {
376376
SEXP s = sd[k];
377377
levelsRaw[k] = s;
378-
hash_set(marks, s, -k-1);
378+
marks = hash_set_shared(marks, s, -k-1);
379+
if (!marks) {
380+
// # nocov start
381+
free(levelsRaw);
382+
error(_("Failed to allocate working memory for %d ordered factor levels of result column %d"), nLevel, idcol+j+1); // # nocov
383+
// # nocov end
384+
}
379385
}
380386
for (int i=0; i<LENGTH(l); ++i) {
381387
SEXP li = VECTOR_ELT(l, i);
@@ -445,7 +451,13 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg, SEXP ignor
445451
}
446452
levelsRaw = tt;
447453
}
448-
hash_set(marks,s,-(++nLevel));
454+
marks = hash_set_shared(marks,s,-(++nLevel));
455+
if (!marks) {
456+
// # nocov start
457+
free(levelsRaw);
458+
error(_("Failed to allocate working memory for %d factor levels of result column %d when reading item %d of item %d"), allocLevel, idcol+j+1, w+1, i+1);
459+
// # nocov end
460+
}
449461
levelsRaw[nLevel-1] = s;
450462
}
451463
int *targetd = INTEGER(target);

0 commit comments

Comments
 (0)