diff --git a/main/utils.c b/main/utils.c index fe2d083d584981477f3b47954870a2f9634336cd..4c0ff3aa8fee4b8d8040280a8b0ea6f024d6975f 100644 --- a/main/utils.c +++ b/main/utils.c @@ -1559,11 +1559,17 @@ int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_ return add_string_pool(mgr, pool_head, needed, file, lineno, func); } + /* if there is an embedded pool, we can't actually release *all* + * pools, we must keep the embedded one. if the caller is about + * to free the structure that contains the stringfield manager + * and embedded pool anyway, it will be freed as part of that + * operation. + */ + if ((needed < 0) && mgr->embedded_pool) { + needed = 0; + } + if (needed < 0) { /* reset all pools */ - if (*pool_head == NULL) { - ast_log(LOG_WARNING, "trying to reset empty pool\n"); - return -1; - } cur = *pool_head; } else if (mgr->embedded_pool) { /* preserve the embedded pool */ preserve = mgr->embedded_pool;