1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Use temp mem context when calling command handlers.

It is safer and more efficient to free memory after each handler completes.

The db command handlers use the server context so update them to use the top context.
This commit is contained in:
David Steele
2021-10-01 18:23:03 -04:00
parent ae40ed6ec9
commit b792a14cd7
2 changed files with 5 additions and 6 deletions

View File

@ -39,11 +39,11 @@ dbOpenProtocol(PackRead *const param, ProtocolServer *const server)
// If the db list does not exist then create it in the prior context (which should be persistent) // If the db list does not exist then create it in the prior context (which should be persistent)
if (dbProtocolLocal.pgClientList == NULL) if (dbProtocolLocal.pgClientList == NULL)
{ {
MEM_CONTEXT_PRIOR_BEGIN() MEM_CONTEXT_BEGIN(memContextTop())
{ {
dbProtocolLocal.pgClientList = lstNewP(sizeof(PgClient *)); dbProtocolLocal.pgClientList = lstNewP(sizeof(PgClient *));
} }
MEM_CONTEXT_PRIOR_END(); MEM_CONTEXT_END();
} }
// Add db to the list // Add db to the list

View File

@ -179,9 +179,8 @@ protocolServerProcess(
// If handler was found then process // If handler was found then process
if (handler != NULL) if (handler != NULL)
{ {
// Send the command to the handler. Run the handler in the server's memory context in case any persistent data // Send the command to the handler
// needs to be stored by the handler. MEM_CONTEXT_TEMP_BEGIN()
MEM_CONTEXT_BEGIN(objMemContext(this))
{ {
// Initialize retries in case of command failure // Initialize retries in case of command failure
bool retry = false; bool retry = false;
@ -229,7 +228,7 @@ protocolServerProcess(
} }
while (retry); while (retry);
} }
MEM_CONTEXT_END(); MEM_CONTEXT_TEMP_END();
} }
// Else check built-in commands // Else check built-in commands
else else