From ac2f9c8138f88a8e160d48affafb22a9c9b9144b Mon Sep 17 00:00:00 2001 From: Vlad Patrascu Date: Fri, 5 Feb 2021 17:30:23 +0200 Subject: [PATCH] b2b_entities: don't pass empty storage packet to entity callbacks Reported in #2387 --- modules/b2b_entities/dlg.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/b2b_entities/dlg.c b/modules/b2b_entities/dlg.c index a3abaa4a26a..8da8a70f82b 100644 --- a/modules/b2b_entities/dlg.c +++ b/modules/b2b_entities/dlg.c @@ -605,13 +605,13 @@ static void run_create_cb_all(struct b2b_callback *cb, int etype) for (i = 0; i < hsize; i++) for (dlg = htable[i].first; dlg; dlg = dlg->next) { - if (bin_init(&storage, &storage_cap, B2BE_STORAGE_BIN_TYPE, - B2BE_STORAGE_BIN_VERS, 0) < 0) { - LM_ERR("Failed to init entity storage buffer\n"); - return; - } - if (dlg->storage.len > 0) { + if (bin_init(&storage, &storage_cap, B2BE_STORAGE_BIN_TYPE, + B2BE_STORAGE_BIN_VERS, 0) < 0) { + LM_ERR("Failed to init entity storage buffer\n"); + return; + } + if (bin_append_buffer(&storage, &dlg->storage) < 0) { LM_ERR("Failed to build entity storage buffer\n"); return; @@ -622,12 +622,15 @@ static void run_create_cb_all(struct b2b_callback *cb, int etype) } cb->cbf(etype, etype == B2B_CLIENT ? &dlg->callid : &dlg->tag[1], - &dlg->param, B2B_EVENT_CREATE, &storage, B2BCB_BACKEND_DB); - - bin_free_packet(&storage); - shm_free(dlg->storage.s); - dlg->storage.s = NULL; - dlg->storage.len = 0; + &dlg->param, B2B_EVENT_CREATE, dlg->storage.len ? &storage : NULL, + B2BCB_BACKEND_DB); + + if (dlg->storage.len) { + bin_free_packet(&storage); + shm_free(dlg->storage.s); + dlg->storage.s = NULL; + dlg->storage.len = 0; + } } }