From: Christian E. Hopps Date: Fri, 27 Sep 2019 18:35:32 +0000 (-0400) Subject: pg: don't leak open files in packet-generator X-Git-Tag: v20.05-rc0~144 X-Git-Url: https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commitdiff_plain;h=19871f25394fa9a4bfb55006092cbcc28b446c04 pg: don't leak open files in packet-generator Fix pg code to close it's open file descriptors before zero'ing the pcap_main structure for re-use. Ticket: VPP-1780 Type: fix Signed-off-by: Christian E. Hopps Change-Id: I32945c6476ae83b8d210ee67ac78db3e8f786f46 --- diff --git a/src/vnet/pg/cli.c b/src/vnet/pg/cli.c index c43ff903e75..f78bb37bf61 100644 --- a/src/vnet/pg/cli.c +++ b/src/vnet/pg/cli.c @@ -93,7 +93,10 @@ pg_capture (pg_capture_args_t * a) pi = pool_elt_at_index (pg->interfaces, a->dev_instance); vec_free (pi->pcap_file_name); + if ((pi->pcap_main.flags & PCAP_MAIN_INIT_DONE)) + pcap_close (&pi->pcap_main); clib_memset (&pi->pcap_main, 0, sizeof (pi->pcap_main)); + pi->pcap_main.file_descriptor = -1; if (a->is_enabled == 0) return 0; diff --git a/src/vppinfra/pcap_funcs.h b/src/vppinfra/pcap_funcs.h index a3a3072f955..125c3bd2517 100644 --- a/src/vppinfra/pcap_funcs.h +++ b/src/vppinfra/pcap_funcs.h @@ -17,6 +17,7 @@ #define included_vppinfra_pcap_funcs_h /** Write out data to output file. */ +clib_error_t *pcap_close (pcap_main_t * pm); clib_error_t *pcap_write (pcap_main_t * pm); /** Read data from file. */