1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00
Commit Graph

4096 Commits

Author SHA1 Message Date
David Steele
aeb7568a0f Remove unused header. 2022-04-28 06:48:02 -04:00
David Steele
5285b9aa7b Fix incorrect test param. 2022-04-27 20:18:18 -04:00
David Steele
eb65a5674d Use OBJ_NEW*() macros in SocketServer object.
This was missed in ccc255d3 when the TLS server was introduced, probably because work on that commit preceded when the macros were introduced in 475b57c8. It would have been easy to miss in a merge.
2022-04-27 11:40:29 -04:00
David Steele
6f2654a5eb Fix leaks in the storage/azure module.
storageAzureHelper() leaked a few Strings which ended up in a long-lived context.

storageAzureNew() failed to make a copy of the endpoint. This worked because storageAzureHelper() leaked the endpoint into the long-lived parent context.

storageAzureRequest() leaked an HttpRequest.

storageAzureInfo() leaked an HttpResponse.

storageAzurePathRemoveCallback() leaked an HttpResponse.

storageAzureRemove() leaked an HttpResponse.
2022-04-26 12:53:55 -04:00
David Steele
be120c746c Refactor and fix leak in storageRepoPathExpression().
storageRepoPathExpression() could leak a StringList. Also refactor to remove unneeded assignments and create the String one time.
2022-04-26 12:27:51 -04:00
David Steele
cca6df872a Refactor functions in postgres/interface module and fix leak.
pgLsnFromWalSegment() leaked two Strings.

Refactor pgLsnRangeToWalSegmentList() to create the StringList in the calling context rather than moving it later.
2022-04-26 12:09:44 -04:00
David Steele
a56fa0eb45 Fix leaks in protocol module.
These leaks were not a big deal individually and there are generally few protocol objects created, but the leaks ended up in mem contexts that persist for most of execution. It makes sense to keep long-lived contexts as tidy as possible.
2022-04-26 11:59:21 -04:00
David Steele
78e912a932 Fix leaks in info module.
*LoadFileCallback() all leaked between retries.

infoPgArchiveId() leaked a String.
2022-04-26 11:20:51 -04:00
David Steele
36b0a9fa58 Fix leaks in db module.
dbFreeResource() leaked ProtocolCommand.

dbTimeMSec() leaked PackRead.
2022-04-26 11:07:05 -04:00
David Steele
78b90e5ad8 Fix leak in configOptionRemote().
A Pack and String were leaked.
2022-04-26 11:03:06 -04:00
David Steele
9a6df39839 Fix spacing. 2022-04-26 11:00:20 -04:00
David Steele
8efb4e1e7f Fix leak in cfgCommandJobRetry().
A Variant was leaked for each retry record.

Also remove an extra linefeed.
2022-04-26 10:58:12 -04:00
David Steele
a8fed52ecb Fix leak in pckReadStrLst().
A String would be leaked on each loop iteration.
2022-04-26 10:53:13 -04:00
David Steele
d7e45f12a5 Refactor httpRequestNew().
Move httpRequestProcess() outside of the object mem context. In case it ever returns a value we don't want that to end up in the object context.
2022-04-26 10:49:04 -04:00
David Steele
cd1cf337ff Fix leak in httpHeaderPutRange().
The range string was leaked.
2022-04-26 10:45:30 -04:00
David Steele
07e2801997 Fix leak in ioFilterGroupResultAllSet().
The PackRead containing the filter results was leaked.
2022-04-26 10:39:28 -04:00
David Steele
3310decf8e Add missing FUNCTION_TEST*() macros. 2022-04-26 10:36:27 -04:00
David Steele
7eed9730aa Fix leak in cipherBlockNew().
The string used to look up the cipher type was leaked.
2022-04-26 10:34:10 -04:00
David Steele
6eed4125e6 Improved memory management in the common/exit module.
Refactor so that error detail is only logged in one place. This reduces calls to exitErrorDetail() and LOG_INTERNAL_FMT().

Fix minor leaks in exitErrorDetail() and exitSafe().
2022-04-26 10:29:48 -04:00
David Steele
fa6c68cb02 Mem allocation cleanup in command/verify module.
Move the temp mem context out of verifyJobCallback() into verifyBackup() and verifyArchive(). This makes it clearer that verifyJobCallback() allocates no memory and reduces mem usage when both verifyBackup() and verifyArchive() are called.

Update verifyErrorMsg() to return zero-terminated strings to save on allocations. The output of this function is used when formatting strings so this is also simpler. Do a similar thing in verifyRender().

Also fix a minor leak in verifyInfoFile().
2022-04-26 10:18:24 -04:00
David Steele
3f7c8bc923 Fix object allocations in incorrect mem context in execOpen().
Object variables were begin allocated in the calling context rather than the object context.

This is not a live bug because Exec objects are currently created and opened in a long-lived context.
2022-04-26 10:15:47 -04:00
Reid Thompson
4dbe76a5bb Fix comment formatting. 2022-04-26 07:33:57 -04:00
David Steele
41f9d69edc Combine functions in the command/stanza module into one function.
It is not clear why these were split out, but it probably had something to do with testing before storageList() could return NULL for an empty directory.

Also remove the tests that depended on a boolean return, which are no longer needed for coverage.
2022-04-25 15:38:49 -04:00
David Steele
55a828f999 Add temporary mem contexts and fix a leak in the command/restore module.
restoreRecoveryConf() and restoreRecoveryWriteConf() do enough work to deserve their own memory contexts.

restoreFilePgPath() was leaking a String every time it was called, which could be a lot.

Also fix a spacing issue.
2022-04-25 15:03:37 -04:00
David Steele
4e7414d48f Add temporary mem contexts in the command/help module.
These were not really leaks since memory was being freed by the calling function, but these functions do enough work to deserve their own memory contexts.
2022-04-25 14:49:08 -04:00
David Steele
fd295f002b Add temporary mem context to removeExpiredBackup().
This was not really a leak since memory was being freed by the calling function, but this function does enough work to deserve its own memory context.

Also fixed a doubled semicolon.
2022-04-25 14:19:10 -04:00
David Steele
9314be36b1 Improve result declaration in backupRegExp().
No need to set this to NULL when the initial value can be used instead.
2022-04-25 14:14:29 -04:00
David Steele
5b5dbe0e7e Fix memory leaks in archivePushDrop().
A string was leaked for every file processed.

Since the list can be quite large it also makes sense to reset the context occasionally.
2022-04-25 13:29:43 -04:00
David Steele
c3b08f71ce Fix formatting in common/string module. 2022-04-25 13:26:09 -04:00
David Steele
40ef64f2be Fix memory leaks in archivePushFile().
The errorList is only used when throwing an error and the joined list is not needed after the error is thrown, so put both in the temp mem context.
2022-04-25 12:59:46 -04:00
David Steele
774db65086 Remove useless context switches in archiveGetFile()/archivePushFile().
These context switches do nothing since the list is already in the prior context.
2022-04-25 12:55:51 -04:00
David Steele
582c3dab4c Add strLstAddSub*() and strLstAddSubZ*() functions.
These help with readability and remove a cause of leaks.
2022-04-25 12:32:33 -04:00
David Steele
ff45f463cf Use strLstAddZ() instead of strLstAdd() where possible.
Using STRDEF() to convert the zero-terminated string to a String has no performance advantage but generates more code.
2022-04-25 11:58:30 -04:00
David Steele
7900660d3a Add strLstNewFmt().
Simplifies adding a formatted string to a list and removes a common cause of leaks.
2022-04-25 11:47:43 -04:00
David Steele
3475514b61 Fix memory leak in archiveAsyncErrorClear().
A string was leaked on each call.
2022-04-25 10:57:36 -04:00
David Steele
23d645b5e7 Fix outdated comment. 2022-04-25 10:52:13 -04:00
David Steele
699f15dd2b Remove THIS_MEM_CONTEXT() macro.
objMemContext(this) performs the same task and is easier to read.

Most instances of this macro were removed by 6e7be3c0.
2022-04-25 09:24:00 -04:00
David Steele
6e7be3c052 Add MEM_CONTEXT_OBJ_*() macros.
These provide a standard way to switch to an object mem context.

Update the two different patterns that were used before to the new macros.
2022-04-25 09:12:25 -04:00
David Steele
45c3f4d53c
Improve JSON handling.
Previously read/writing JSON required parsing/render via a variant, which add many more memory allocations and loops.

Instead allow JSON to be read/written serially to improve performance and simplify the code. This also allows us to get rid of many String and Variant constant which are no longer required.

The goal is to be able to read/write very large (e.g. gigabyte manifest) JSON structures, which would not be practical with the current code.

Note that external JSON (GCS, S3, etc) is still handled using variants. Converting these will require more consideration about key ordering since it cannot be guaranteed as in our own formats.
2022-04-25 09:06:26 -04:00
David Steele
58f24568f5 Add ASSERT_PARAM() macro.
Allows adding a parameter to a function that is used only for assertions.
2022-04-25 08:25:48 -04:00
David Steele
1e2b545ba4 Require type for FUNCTION_TEST_RETURN*() macros.
This allows code to run after the return type has been generated in the case where it is an expression.

No new functionality here yet, but this will be used by a future commit that audits memory usage.
2022-04-24 19:19:46 -04:00
David Steele
91bbe81059 Add SIZE_OF_STRUCT_MEMBER() macro.
Gets the size of a struct member, which requires a bit of additional syntax.
2022-04-22 09:14:12 -04:00
David Steele
a2eee156b5 Fix instances where STRDEF() was used instead of STR().
In practice this didn't cause problems because the string buffer was still valid and strSize() was not being called.
2022-04-21 18:23:17 -04:00
David Steele
627921c72a Add STR_SIZE() macro.
This allows efficiently creating strings where the length is already known and simplifies the STR() and STRDEF() macros.
2022-04-21 08:35:31 -04:00
David Steele
1ce613a24d Use STRDEF() instead of STR() in command/help module.
STRDEF() is more efficient since this is a constant string.
2022-04-21 08:34:03 -04:00
David Steele
4daddebaca Add ASSERT_DECLARE() macro.
Declare variables that will be used by later assertions with the goal of making them easier to read and maintain.

This is particularly useful for variables that are used more than once and require a lot of syntax to extract.
2022-04-21 08:07:22 -04:00
David Steele
e18b70bf55 Allow *RETURN*() macros to accept struct initializers.
Struct initializers look like multiple parameters in a macro so use __VA_ARGS__ to reconstruct them.
2022-04-21 07:45:59 -04:00
David Steele
ea4d73f375 Fix ordering of backup-lsn-stop field in command/restore unit test.
All fields should be alphabetical. Currently the read code is tolerant of this, but that will not always be the case.

Fields are always written alphabetically so this is just a test issue introduced by d8d41321.
2022-04-20 19:56:26 -04:00
David Steele
cb7a5f1ef3 Add JSON error when value does not parse in Ini object.
If the JSON value fails to parse it is helpful to have the error message, at least for debugging.
2022-04-20 19:49:23 -04:00
David Steele
da6b4abc58 Handle missing archive start/stop in info/info backup unit test.
This is not a very realistic case since archive start/stop are always written, but it appears in many other unit tests so it should also be tested here.
2022-04-20 19:41:28 -04:00