From 62b2188d8282e5dda9a388a851cd701434f69124 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 7 Oct 2015 13:10:17 +0100 Subject: [PATCH] Add routine to free fstring mapped ftoks. --- src/libutil/fstring.c | 11 +++++++++++ src/libutil/fstring.h | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index 232b0021c..e63912c9a 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -319,3 +319,14 @@ rspamd_ftok_cmp (const rspamd_ftok_t *s1, return s1->len - s2->len; } + +void +rspamd_fstring_mapped_ftok_free (gpointer p) +{ + rspamd_ftok_t *tok = p; + rspamd_fstring_t *storage; + + storage = (rspamd_fstring_t *) (tok->begin - 2 * sizeof (gsize)); + rspamd_fstring_free (storage); + g_slice_free1 (sizeof (*tok), tok); +} \ No newline at end of file diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index abb69dcbc..5ca74f457 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -128,4 +128,14 @@ gint rspamd_ftok_casecmp (const rspamd_ftok_t *s1, gint rspamd_ftok_cmp (const rspamd_ftok_t *s1, const rspamd_ftok_t *s2); +/** + * Free fstring_t that is mapped to ftok_t + * + * | len | allocated | -- fstring_t + * -- tok + * + * tok is expected to be allocated with g_slice_alloc + */ +void rspamd_fstring_mapped_ftok_free (gpointer p); + #endif -- 2.39.5