summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/Buffer.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2011-04-13 14:50:10 +0200
committerJose <jose@zeroc.com>2011-04-13 14:50:10 +0200
commit0eb8d99e1e2938171e548be54ca327fd722679e9 (patch)
tree226bfb56afd978c2ca20e714ecaf2f99a926bc9c /cpp/src/Ice/Buffer.cpp
parent4851 - slice2cpp bug for string literals (diff)
downloadice-0eb8d99e1e2938171e548be54ca327fd722679e9.tar.bz2
ice-0eb8d99e1e2938171e548be54ca327fd722679e9.tar.xz
ice-0eb8d99e1e2938171e548be54ca327fd722679e9.zip
4780 - Buffer class should reset _capacity if the buffer can't be allocated
Diffstat (limited to 'cpp/src/Ice/Buffer.cpp')
-rw-r--r--cpp/src/Ice/Buffer.cpp15
1 files changed, 5 insertions, 10 deletions
diff --git a/cpp/src/Ice/Buffer.cpp b/cpp/src/Ice/Buffer.cpp
index 9949e90a102..cab27569b5e 100644
--- a/cpp/src/Ice/Buffer.cpp
+++ b/cpp/src/Ice/Buffer.cpp
@@ -56,6 +56,7 @@ IceInternal::Buffer::Container::clear()
void
IceInternal::Buffer::Container::reserve(size_type n)
{
+ size_type c = _capacity;
if(n > _capacity)
{
_capacity = std::max<size_type>(n, std::min(2 * _capacity, _maxCapacity));
@@ -70,19 +71,13 @@ IceInternal::Buffer::Container::reserve(size_type n)
return;
}
- if(_buf)
- {
- _buf = reinterpret_cast<pointer>(::realloc(_buf, _capacity));
- }
- else
- {
- _buf = reinterpret_cast<pointer>(::malloc(_capacity));
- }
-
- if(!_buf)
+ pointer p = reinterpret_cast<pointer>(::realloc(_buf, _capacity));
+ if(!p)
{
+ _capacity = c; // Restore the previous capacity.
SyscallException ex(__FILE__, __LINE__);
ex.error = getSystemErrno();
throw ex;
}
+ _buf = p;
}