diff --git a/msg.c b/msg.c index 52a59e7..adab384 100644 --- a/msg.c +++ b/msg.c @@ -204,6 +204,7 @@ struct ptp_message *msg_allocate(void) if (m) { memset(m, 0, sizeof(*m)); m->refcnt = 1; + TAILQ_INIT(&m->tlv_list); } return m; @@ -447,12 +448,19 @@ void msg_print(struct ptp_message *m, FILE *fp) void msg_put(struct ptp_message *m) { + struct tlv_extra *extra; + m->refcnt--; - if (!m->refcnt) { - pool_stats.count++; - pool_debug("recycle", m); - TAILQ_INSERT_HEAD(&msg_pool, m, list); + if (m->refcnt) { + return; } + pool_stats.count++; + pool_debug("recycle", m); + while ((extra = TAILQ_FIRST(&m->tlv_list)) != NULL) { + TAILQ_REMOVE(&m->tlv_list, extra, list); + tlv_extra_recycle(extra); + } + TAILQ_INSERT_HEAD(&msg_pool, m, list); } int msg_sots_missing(struct ptp_message *m) diff --git a/msg.h b/msg.h index 12e6ce8..3d67c23 100644 --- a/msg.h +++ b/msg.h @@ -219,6 +219,11 @@ struct ptp_message { * sent to. */ struct address address; + /** + * List of TLV descriptors. Each item in the list contains + * pointers to the appended TLVs. + */ + TAILQ_HEAD(tlv_list, tlv_extra) tlv_list; /** * Contains the number of TLVs in the suffix. */