We have the ReleaseData API which is made for that. Take a look at https://redmine.openinfosecfoundation.org/projects/suricata/wiki/Packet_Acquisition_API#Packet-release-mechanism
Basically if p->ReleaseData is a callback function which is called when cleaning the file.
I wonder if it is not possible to get rid of PKT_MPIPE by using this API (or if not we can make it evolve).