diff options
author | Paolo Carlini <pcarlini@suse.de> | 2004-01-30 13:23:42 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2004-01-30 13:23:42 +0000 |
commit | d1615643e511bab93bdf275303aab9468505bc79 (patch) | |
tree | 2e503ee03b3527329af5598d5b7ce79ff5af683d /libstdc++-v3 | |
parent | 1e0f41c9d2779b52fa385510c4c3375be596f1ff (diff) | |
download | gcc-d1615643e511bab93bdf275303aab9468505bc79.zip gcc-d1615643e511bab93bdf275303aab9468505bc79.tar.gz gcc-d1615643e511bab93bdf275303aab9468505bc79.tar.bz2 |
basic_string.tcc (_Rep::_S_create): Never allocate a string bigger than max_size()...
2004-01-30 Paolo Carlini <pcarlini@suse.de>
* include/bits/basic_string.tcc (_Rep::_S_create):
Never allocate a string bigger than max_size(); always keep
__capacity and __size in sync to avoid memory leaks at
deallocation time.
From-SVN: r76955
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 7 |
2 files changed, 12 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e13c44a..0273958 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2004-01-30 Paolo Carlini <pcarlini@suse.de> + * include/bits/basic_string.tcc (_Rep::_S_create): + Never allocate a string bigger than max_size(); always keep + __capacity and __size in sync to avoid memory leaks at + deallocation time. + +2004-01-30 Paolo Carlini <pcarlini@suse.de> + * include/bits/basic_string.tcc (_S_construct(_InIterator, _InIterator, const _Alloc&, input_iterator_tag)): Simplify the double loop, streamline. diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index a478a4c..e35b305 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -520,7 +520,10 @@ namespace std - (__size + __malloc_header_size) % __pagesize); __capacity += __extra / sizeof(_CharT); - __size += __extra; + // Never allocate a string bigger than _S_max_size. + if (__capacity > _S_max_size) + __capacity = _S_max_size; + __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); } else if (__size > __subpagesize) { @@ -528,7 +531,7 @@ namespace std - (__size + __malloc_header_size) % __subpagesize); __capacity += __extra / sizeof(_CharT); - __size += __extra; + __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); } // NB: Might throw, but no worries about a leak, mate: _Rep() |