diff --git a/src/functions.c b/src/functions.c index d5bab4128b..3f67816e91 100644 --- a/src/functions.c +++ b/src/functions.c @@ -186,7 +186,12 @@ void functionsLibCtxClearCurrent(int async) { } /* Free the given functions ctx */ -void freeFunctionsSync(functionsLibCtx *functions_lib_ctx) { +void functionsLibCtxFreeGeneric(functionsLibCtx *functions_lib_ctx, int async) { + if (async) { + freeFunctionsAsync(functions_lib_ctx); + return; + } + functionsLibCtxClear(functions_lib_ctx); dictRelease(functions_lib_ctx->functions); dictRelease(functions_lib_ctx->libraries); @@ -195,18 +200,14 @@ void freeFunctionsSync(functionsLibCtx *functions_lib_ctx) { } /* Free the given functions ctx */ -void functionsLibCtxFree(functionsLibCtx *functions_lib_ctx, int async) { - if (async) { - freeFunctionsAsync(functions_lib_ctx); - } else { - freeFunctionsSync(functions_lib_ctx); - } +void functionsLibCtxFree(functionsLibCtx *functions_lib_ctx) { + functionsLibCtxFreeGeneric(functions_lib_ctx, 0); } /* Swap the current functions ctx with the given one. * Free the old functions ctx. */ void functionsLibCtxSwapWithCurrent(functionsLibCtx *new_lib_ctx, int async) { - functionsLibCtxFree(curr_functions_lib_ctx, async); + functionsLibCtxFreeGeneric(curr_functions_lib_ctx, async); curr_functions_lib_ctx = new_lib_ctx; } @@ -798,7 +799,7 @@ void functionRestoreCommand(client *c) { addReply(c, shared.ok); } if (functions_lib_ctx) { - functionsLibCtxFree(functions_lib_ctx, server.lazyfree_lazy_user_flush); + functionsLibCtxFreeGeneric(functions_lib_ctx, server.lazyfree_lazy_user_flush); } } diff --git a/src/functions.h b/src/functions.h index eeda2b94b3..429405bb2d 100644 --- a/src/functions.h +++ b/src/functions.h @@ -134,8 +134,7 @@ size_t functionsLibCtxFunctionsLen(functionsLibCtx *functions_ctx); functionsLibCtx *functionsLibCtxGetCurrent(void); functionsLibCtx *functionsLibCtxCreate(void); void functionsLibCtxClearCurrent(int async); -void freeFunctionsSync(functionsLibCtx *functions_lib_ctx); -void functionsLibCtxFree(functionsLibCtx *functions_lib_ctx, int async); +void functionsLibCtxFree(functionsLibCtx *functions_lib_ctx); void functionsLibCtxClear(functionsLibCtx *lib_ctx); void functionsLibCtxSwapWithCurrent(functionsLibCtx *new_lib_ctx, int async); diff --git a/src/lazyfree.c b/src/lazyfree.c index b20b1c520d..6176b43440 100644 --- a/src/lazyfree.c +++ b/src/lazyfree.c @@ -64,7 +64,7 @@ void lazyFreeLuaScripts(void *args[]) { void lazyFreeFunctionsCtx(void *args[]) { functionsLibCtx *functions_lib_ctx = args[0]; size_t len = functionsLibCtxFunctionsLen(functions_lib_ctx); - functionsLibCtxFree(functions_lib_ctx, 0); + functionsLibCtxFree(functions_lib_ctx); atomic_fetch_sub_explicit(&lazyfree_objects, len, memory_order_relaxed); atomic_fetch_add_explicit(&lazyfreed_objects, len, memory_order_relaxed); } @@ -240,7 +240,7 @@ void freeFunctionsAsync(functionsLibCtx *functions_lib_ctx) { memory_order_relaxed); bioCreateLazyFreeJob(lazyFreeFunctionsCtx, 1, functions_lib_ctx); } else { - freeFunctionsSync(functions_lib_ctx); + functionsLibCtxFree(functions_lib_ctx); } } diff --git a/src/replication.c b/src/replication.c index 96c87a7497..0e7a1947fe 100644 --- a/src/replication.c +++ b/src/replication.c @@ -2266,7 +2266,7 @@ void readSyncBulkPayload(connection *conn) { NULL); disklessLoadDiscardTempDb(diskless_load_tempDb); - functionsLibCtxFree(temp_functions_lib_ctx, 0); + functionsLibCtxFree(temp_functions_lib_ctx); serverLog(LL_NOTICE, "PRIMARY <-> REPLICA sync: Discarding temporary DB in background"); } else { /* Remove the half-loaded data in case we started with an empty replica. */