clibpcapfclosedouble-free

Double free when use pcap_close and fclose simultaneously


FILE* file = fopen(some file)

pcap_t* pd = pcap_fopen_offline(file)

pcap_close(pd)

fclose(file)

This code occurs double free error.

Could you explain about this happening?

My Guess is that pd and file pointers are sharing some datas.


Solution

  • As the documentation says, the pcap_close function closes the files associated with the pcap_t structure passed to it. Closing the file again with fclose is an error.