Skip to content

Commit dcdc683

Browse files
authored
Merge pull request #131 from freysteinn/master
basic-solutions: Prevent exhaustion of file descriptors in xdp_stats
2 parents 4d4b258 + eb4d557 commit dcdc683

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

basic-solutions/xdp_stats.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,13 @@ static int stats_poll(const char *pin_dir, int map_fd, __u32 id,
213213
return EXIT_FAIL_BPF;
214214
} else if (id != info.id) {
215215
printf("BPF map xdp_stats_map changed its ID, restarting\n");
216+
close(map_fd);
216217
return 0;
217218
}
218219

219220
stats_collect(map_fd, map_type, &record);
220221
stats_print(&record, &prev);
222+
close(map_fd);
221223
sleep(interval);
222224
}
223225

@@ -275,6 +277,7 @@ int main(int argc, char **argv)
275277
err = check_map_fd_info(&info, &map_expect);
276278
if (err) {
277279
fprintf(stderr, "ERR: map via FD not compatible\n");
280+
close(stats_map_fd);
278281
return err;
279282
}
280283
if (verbose) {
@@ -287,6 +290,7 @@ int main(int argc, char **argv)
287290
}
288291

289292
err = stats_poll(pin_dir, stats_map_fd, info.id, info.type, interval);
293+
close(stats_map_fd);
290294
if (err < 0)
291295
return err;
292296
}

0 commit comments

Comments
 (0)