aboutsummaryrefslogtreecommitdiffstats
path: root/g10/free-packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/free-packet.c')
-rw-r--r--g10/free-packet.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/g10/free-packet.c b/g10/free-packet.c
index 4cf80a4a1..535a17fb8 100644
--- a/g10/free-packet.c
+++ b/g10/free-packet.c
@@ -394,18 +394,40 @@ free_plaintext( PKT_plaintext *pt )
xfree (pt);
}
+
/****************
* Free the packet in PKT.
*/
void
-free_packet (PACKET *pkt)
+free_packet (PACKET *pkt, parse_packet_ctx_t parsectx)
{
if (!pkt || !pkt->pkt.generic)
- return;
+ {
+ if (parsectx && parsectx->last_pkt)
+ {
+ if (parsectx->free_last_pkt)
+ {
+ free_packet (parsectx->last_pkt, NULL);
+ parsectx->free_last_pkt = 0;
+ }
+ parsectx->last_pkt = NULL;
+ }
+ return;
+ }
if (DBG_MEMORY)
log_debug ("free_packet() type=%d\n", pkt->pkttype);
+ /* If we have a parser context holding PKT then do not free the
+ * packet but set a flag that the packet in the parser context is
+ * now a deep copy. */
+ if (parsectx && parsectx->last_pkt == pkt && !parsectx->free_last_pkt)
+ {
+ parsectx->free_last_pkt = 1;
+ pkt->pkt.generic = NULL;
+ return;
+ }
+
switch (pkt->pkttype)
{
case PKT_SIGNATURE: