Skip to content

Commit 46ec56c

Browse files
committed
Guarding memory usage.
1 parent 6202ea3 commit 46ec56c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/build_filter.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,14 @@ int main(int argc, char **argv) {
167167
if (strcmp("binaryfuse8", filtername) == 0) {
168168
start = clock();
169169
binary_fuse8_t filter;
170-
binary_fuse8_allocate(array_size, &filter);
171-
binary_fuse8_populate(array, array_size, &filter);
170+
if(!binary_fuse8_allocate(array_size, &filter)) {
171+
printf("failed to allocate memory.\n");
172+
return EXIT_FAILURE;
173+
}
174+
if(!binary_fuse8_populate(array, array_size, &filter)){
175+
printf("failed to build the filter, do you have sufficient memory?\n");
176+
return EXIT_FAILURE;
177+
}
172178
end = clock();
173179
printf("Done in %.3f seconds.\n", (float)(end - start) / CLOCKS_PER_SEC);
174180
if (verify) {
@@ -233,8 +239,14 @@ int main(int argc, char **argv) {
233239
} else if (strcmp("xor8", filtername) == 0) {
234240
start = clock();
235241
xor8_t filter;
236-
xor8_allocate(array_size, &filter);
237-
xor8_buffered_populate(array, array_size, &filter);
242+
if(!xor8_allocate(array_size, &filter)) {
243+
printf("failed to allocate memory.\n");
244+
return EXIT_FAILURE;
245+
}
246+
if(!xor8_buffered_populate(array, array_size, &filter)) {
247+
printf("failed to build the filter, do you have sufficient memory?\n");
248+
return EXIT_FAILURE;
249+
}
238250
end = clock();
239251
printf("Done in %.3f seconds.\n", (float)(end - start) / CLOCKS_PER_SEC);
240252
if (verify) {

0 commit comments

Comments
 (0)