This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[PATCH][libstdc++-v3 parallel mode] Fix memory leaks in multiway_merge
- From: Johannes Singler <singler at ira dot uka dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 10 Sep 2009 11:41:51 +0200
- Subject: [PATCH][libstdc++-v3 parallel mode] Fix memory leaks in multiway_merge
This patch fixes two memory leaks (and non-called destructors) in
multiway_merge.
Tested x86_64-unknown-linux-gnu: No regressions
Please approve for mainline and gcc-4_4-branch.
2009-09-10 Johannes Singler <singler@ira.uka.de>
* include/parallel/multiway_merge.h
(multiway_merge_exact_splitting): Deallocate borders correctly.
(parallel_multiway_merge): Remove unnecessarily complicated
allocation, random access iterators are default-constructible.
Deallocate ne_seqs correctly.
Johannes
Index: include/parallel/multiway_merge.h
===================================================================
--- include/parallel/multiway_merge.h (revision 151474)
+++ include/parallel/multiway_merge.h (working copy)
@@ -1224,8 +1224,8 @@
offsets[num_threads - 1].begin(), comp);
}
}
+ delete[] borders;
-
for (int slab = 0; slab < num_threads; ++slab)
{
// For each slab / processor.
@@ -1305,11 +1305,8 @@
std::iterator_traits<RandomAccessIterator1>::value_type value_type;
// Leave only non-empty sequences.
- std::pair<RandomAccessIterator1, RandomAccessIterator1>* ne_seqs =
- static_cast<std::pair<RandomAccessIterator1, RandomAccessIterator1>*>(
- ::operator new(
- sizeof(std::pair<RandomAccessIterator1, RandomAccessIterator1>)
- * (seqs_end - seqs_begin)));
+ typedef std::pair<RandomAccessIterator1, RandomAccessIterator1> seq_type;
+ seq_type* ne_seqs = new seq_type[seqs_end - seqs_begin];
int k = 0;
difference_type total_length = 0;
for (RandomAccessIteratorIterator raii = seqs_begin;
@@ -1319,9 +1316,7 @@
if(seq_length > 0)
{
total_length += seq_length;
- //ne_seqs[k] = *raii;
- new(&(ne_seqs[k++]))
- std::pair<RandomAccessIterator1, RandomAccessIterator1>(*raii);
+ ne_seqs[k++] = *raii;
}
}
@@ -1331,7 +1326,7 @@
if (total_length == 0 || k == 0)
{
- ::operator delete(ne_seqs);
+ delete[] ne_seqs;
return target;
}
@@ -1366,8 +1361,7 @@
for (int c = 0; c < k; ++c)
target_position += pieces[iam][c].first;
- std::pair<RandomAccessIterator1, RandomAccessIterator1>* chunks
- = new std::pair<RandomAccessIterator1, RandomAccessIterator1>[k];
+ seq_type* chunks = new seq_type[k];
for (int s = 0; s < k; ++s)
{
@@ -1399,6 +1393,7 @@
}
delete[] pieces;
+ delete[] ne_seqs;
return target + length;
}