I think this is the fix. The first bit is walking off the list. The 2nd part might help for programs which call libpcap repeatedly.
Index: gencode.c =================================================================== RCS file: /cvs/src/lib/libpcap/gencode.c,v retrieving revision 1.61 diff -u -r1.61 gencode.c --- gencode.c 28 Mar 2022 02:58:06 -0000 1.61 +++ gencode.c 27 May 2022 20:30:53 -0000 @@ -207,12 +207,13 @@ for (i = 0; i <= cur_membag; i++) { if (membag[i].ptrs == NULL) continue; - for (j = 0; j <= membag[i].slot; j++) + for (j = 0; j < membag[i].slot; j++) free(membag[i].ptrs[j]); free(membag[i].ptrs); membag[i].ptrs = NULL; membag[i].slot = membag[i].total = 0; } + cur_membag = 0; } /*