The struct_sgl object from generate_shingles_from_string_tokens() was only
deleted when pool == nullptr, causing memory leaks when a memory pool was
active. Now struct_sgl is always deleted after copying to res, regardless
of pool allocation method.
return nullptr;
}
- /* Allocate result */
+ /* Allocate result after all early exit checks to avoid leaks */
struct rspamd_html_shingle *res;
if (pool) {
res = static_cast<rspamd_html_shingle *>(rspamd_mempool_alloc0(pool, sizeof(*res)));
if (struct_sgl) {
std::memcpy(&res->structure_shingles, struct_sgl, sizeof(struct rspamd_shingle));
- if (pool == nullptr) {
- delete struct_sgl;
- }
+ /* Always delete struct_sgl after copying, regardless of pool */
+ delete struct_sgl;
}
else {
std::memset(&res->structure_shingles, 0, sizeof(struct rspamd_shingle));