mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Refactor error logic to make sure Db object gets freed immediately.
Because db can be reset to NULL on an error in the try block we need nested try blocks to ensure that db is non-NULL and can be freed on an error after being created. This is not a production issue because the db will be freed when the temp mem context is freed, but it does affect reproducibility in the tests and is a bit tidier.
This commit is contained in:
parent
61c4f64895
commit
ac870b42de
@ -72,15 +72,25 @@ dbGet(bool primaryOnly, bool primaryRequired)
|
||||
TRY_BEGIN()
|
||||
{
|
||||
db = dbGetId(pgIdx + 1);
|
||||
dbOpen(db);
|
||||
standby = dbIsStandby(db);
|
||||
|
||||
// This needs to be nested because db can be reset to NULL on an error in the outer try but we need the pointer
|
||||
// to be able to free it.
|
||||
TRY_BEGIN()
|
||||
{
|
||||
dbOpen(db);
|
||||
standby = dbIsStandby(db);
|
||||
}
|
||||
CATCH_ANY()
|
||||
{
|
||||
dbFree(db);
|
||||
RETHROW();
|
||||
}
|
||||
TRY_END();
|
||||
}
|
||||
CATCH_ANY()
|
||||
{
|
||||
dbFree(db);
|
||||
db = NULL;
|
||||
|
||||
LOG_WARN("unable to check pg-%u: [%s] %s", pgIdx + 1, errorTypeName(errorType()), errorMessage());
|
||||
db = NULL;
|
||||
}
|
||||
TRY_END();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user