From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2F2A0469719 for ; Fri, 13 Nov 2020 15:28:08 +0300 (MSK) Received: by mail-lf1-f65.google.com with SMTP id s30so13561128lfc.4 for ; Fri, 13 Nov 2020 04:28:08 -0800 (PST) From: Cyrill Gorcunov Date: Fri, 13 Nov 2020 15:28:02 +0300 Message-Id: <20201113122802.253784-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH] func: clean the module cache on first load error List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tml Cc: Vladislav Shpilevoy In case if we're loading a fresh module we put it into a module's cache first which allows us to not reload same module twice (say there could be several functions in same module). But if the module is loaded for the first time and symbol resolution failed we continue keeping this module loaded even if there may be no more use of it. Thus make a cleanup if needed. There is no portable way to verify via test as far as I know, just manually via "lsof -p `pidof tarantool`". Fixes #5475 Reported-by: Vladislav Shpilevoy Signed-off-by: Cyrill Gorcunov --- src/box/func.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/box/func.c b/src/box/func.c index 8087c953f..9909cee45 100644 --- a/src/box/func.c +++ b/src/box/func.c @@ -528,10 +528,9 @@ func_c_load(struct func_c *func) struct func_name name; func_split_name(func->base.def->name, &name); - struct module *module = module_cache_find(name.package, - name.package_end); - if (module == NULL) { - /* Try to find loaded module in the cache */ + struct module *cached, *module; + cached = module_cache_find(name.package, name.package_end); + if (cached == NULL) { module = module_load(name.package, name.package_end); if (module == NULL) return -1; @@ -539,11 +538,27 @@ func_c_load(struct func_c *func) module_delete(module); return -1; } + } else { + module = cached; } func->func = module_sym(module, name.sym); - if (func->func == NULL) + if (func->func == NULL) { + if (cached == NULL) { + /* + * In case if it was a first load we should + * clean the cache immediately otherwise + * the module continue being referenced even + * if there will be no use of it. + * + * Note the module_sym set an error thus be + * careful to not wipe it. + */ + module_cache_del(name.package, name.package_end); + module_delete(module); + } return -1; + } func->module = module; rlist_add(&module->funcs, &func->item); return 0; -- 2.26.2