Skip to content

Commit fced6f4

Browse files
authored
Merge pull request #49621 from makortel/autoPtrMemFix
Fix memory leak in `auto_ptr` read rule test
2 parents ae223c1 + c304144 commit fced6f4

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

DataFormats/TestObjects/src/classes.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@
4848
// related to SchemaEvolutionTestObjects.h
4949
#ifndef DataFormats_TestObjects_USE_OLD
5050

51-
// The following is from an example by Jakob Blomer from the ROOT team
51+
// The following is from an example from ROOT team
52+
// roottest/root/io/autoptr/TestAutoPtr_v3.hxx
5253
namespace edmtest::compat {
5354
template <typename T>
5455
struct deprecated_auto_ptr {
55-
// We use compat_auto_ptr only to assign the wrapped raw pointer
56+
// We use deprecated_auto_ptr only to assign the wrapped raw pointer
5657
// to a unique pointer in an I/O customization rule.
57-
// Therefore, we don't delete on destruction (because ownership
58-
// gets transferred to the unique pointer).
58+
// However, since the deprecated_auto_ptr object can be reused, it is essential to always reset the
59+
// value after using it, so we can safely delete it (it should always be nullptr)
5960

60-
// ~deprecated_auto_ptr() { delete _M_ptr; }
61+
~deprecated_auto_ptr() { delete _M_ptr; }
6162

6263
T *_M_ptr = nullptr;
6364
};

DataFormats/TestObjects/src/classes_def.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ exception when running testMissingDictionaryChecking_cfg.py.
418418
<ioread sourceClass="std::auto_ptr<edmtest::SchemaEvolutionContained>" targetClass="edmtest::compat::deprecated_auto_ptr<edmtest::SchemaEvolutionContained>"/>
419419
<ioread sourceClass="edmtest::SchemaEvolutionAutoPtrToUniquePtr" version="[3]" targetClass="edmtest::SchemaEvolutionAutoPtrToUniquePtr" source="edmtest::compat::deprecated_auto_ptr<edmtest::SchemaEvolutionContained> contained_" target="contained_">
420420
<![CDATA[
421-
contained_.release(); contained_.reset(onfile.contained_._M_ptr);
421+
contained_.reset(onfile.contained_._M_ptr); onfile.contained_._M_ptr = nullptr;
422422
]]>
423423
</ioread>
424424
<class name="edmtest::SchemaEvolutionCArrayToStdArray" ClassVersion="4">

0 commit comments

Comments
 (0)