summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Summers <ben@fluffy.co.uk>2006-01-06 10:28:03 +0000
committerBen Summers <ben@fluffy.co.uk>2006-01-06 10:28:03 +0000
commit18d03eb51a36ad7d31edace38cff956e90f3fa19 (patch)
tree17e0e43d5f0c059ec446e3e59a8df012a3915cf1 /lib
parentbe32ddee052ee73f74e744a2e907865667b042fa (diff)
Change handling of static buffer in filename encoding and decoding to avoid double free on exit under Darwin -- maybe a runtime issue?
Diffstat (limited to 'lib')
-rw-r--r--lib/backupclient/BackupStoreFilenameClear.cpp54
1 files changed, 22 insertions, 32 deletions
diff --git a/lib/backupclient/BackupStoreFilenameClear.cpp b/lib/backupclient/BackupStoreFilenameClear.cpp
index 3069f612..7c36d5b3 100644
--- a/lib/backupclient/BackupStoreFilenameClear.cpp
+++ b/lib/backupclient/BackupStoreFilenameClear.cpp
@@ -184,28 +184,30 @@ void BackupStoreFilenameClear::MakeClearAvailable() const
// Buffer for encoding and decoding -- do this all in one single buffer to
// avoid lots of string allocation, which stuffs up memory usage.
// These static memory vars are, of course, not thread safe, but we don't use threads.
-#ifndef NDEBUG
-static int sEncDecBufferSize = 2; // small size for debug builds
-#else
-static int sEncDecBufferSize = 256;
-#endif
-static MemoryBlockGuard<uint8_t *> spEncDecBuffer(sEncDecBufferSize);
+static int sEncDecBufferSize = 0;
+static MemoryBlockGuard<uint8_t *> *spEncDecBuffer = 0;
-// fudge to stop leak reporting
-#ifdef BOX_MEMORY_LEAK_TESTING
-namespace
+static void EnsureEncDecBufferSize(int BufSize)
{
- class leak_off
+ if(spEncDecBuffer == 0)
{
- public:
- leak_off()
+ TRACE1("Allocating filename encoding/decoding buffer with size %d\n", BufSize);
+ spEncDecBuffer = new MemoryBlockGuard<uint8_t *>(BufSize);
+ MEMLEAKFINDER_NOT_A_LEAK(spEncDecBuffer);
+ MEMLEAKFINDER_NOT_A_LEAK(*spEncDecBuffer);
+ sEncDecBufferSize = BufSize;
+ }
+ else
+ {
+ if(sEncDecBufferSize < BufSize)
{
- MEMLEAKFINDER_NOT_A_LEAK(spEncDecBuffer);
+ TRACE2("Reallocating filename encoding/decoding buffer from %d to %d\n", sEncDecBufferSize, BufSize);
+ spEncDecBuffer->Resize(BufSize);
+ sEncDecBufferSize = BufSize;
+ MEMLEAKFINDER_NOT_A_LEAK(*spEncDecBuffer);
}
- };
- leak_off dont_report_as_leak;
+ }
}
-#endif
// --------------------------------------------------------------------------
//
@@ -221,16 +223,10 @@ void BackupStoreFilenameClear::EncryptClear(const std::string &rToEncode, Cipher
int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rToEncode.size()) + 4;
// Make sure encode/decode buffer has enough space
- if(sEncDecBufferSize < maxOutSize)
- {
- TRACE2("Reallocating filename encoding/decoding buffer from %d to %d\n", sEncDecBufferSize, maxOutSize);
- spEncDecBuffer.Resize(maxOutSize);
- sEncDecBufferSize = maxOutSize;
- }
+ EnsureEncDecBufferSize(maxOutSize);
// Pointer to buffer
- uint8_t *buffer = spEncDecBuffer;
- MEMLEAKFINDER_NOT_A_LEAK(buffer);
+ uint8_t *buffer = *spEncDecBuffer;
// Encode -- do entire block in one go
int encSize = rCipherContext.TransformBlock(buffer + 2, sEncDecBufferSize - 2, rToEncode.c_str(), rToEncode.size());
@@ -259,16 +255,10 @@ void BackupStoreFilenameClear::DecryptEncoded(CipherContext &rCipherContext) con
int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(size()) + 4;
// Make sure encode/decode buffer has enough space
- if(sEncDecBufferSize < maxOutSize)
- {
- TRACE2("Reallocating filename encoding/decoding buffer from %d to %d\n", sEncDecBufferSize, maxOutSize);
- spEncDecBuffer.Resize(maxOutSize);
- sEncDecBufferSize = maxOutSize;
- }
+ EnsureEncDecBufferSize(maxOutSize);
// Pointer to buffer
- uint8_t *buffer = spEncDecBuffer;
- MEMLEAKFINDER_NOT_A_LEAK(buffer);
+ uint8_t *buffer = *spEncDecBuffer;
// Decrypt
const char *str = c_str() + 2;