majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Segmentation fault (SIGSEGV) on object destruction #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
To reproduce the problem:

std::string MyClass::getValue(const std::string &name) {
    YAML::Node node = this->document.GetValue(name);

    // […]
}

MyClass::~MyClass() {
    // SIGSEGV here
}

I use the SVN version (revision 78)

I guess that the problem is that the copy constructor of a node does not
copy its resources too. When it is freed once, these resources are freed
too. When the original resources are freed (in the class destructor), they
have already been freed and there may be a SIGSEGV.

The attribute in cause seems to be Node::m_pContent.

To correct this issue, just create a new Content instance in m_pContent, or
define the copy constructor as protected or private to forbid the copy, if
the content should not be duplicated.

Original issue reported on code.google.com by paul.mor...@gmail.com on 16 Sep 2008 at 12:11

GoogleCodeExporter commented 9 years ago
By the way, to avoid the problem, I just use the method like:

const YAML::Node &node = this->document.GetValue(name);

Original comment by paul.mor...@gmail.com on 16 Sep 2008 at 12:16

GoogleCodeExporter commented 9 years ago
Thanks. I intended to have YAML::Node be non-copyable (and I use the method you 
described above), so I added private, unimplemented copy and assignment.

This (having YAML::Node be non-copyable) may be changed eventually, if I ever 
add 
creation functions, but for now it should just give you a compile error.

Original comment by jbe...@gmail.com on 19 Sep 2008 at 2:47

GoogleCodeExporter commented 9 years ago
By the way, I didn't implement copy functionality because I don't see a use for 
it 
(given that you can't create YAML documents). However, if you have a reason to 
do so, 
please let me know, and I'll add it!

Original comment by jbe...@gmail.com on 19 Sep 2008 at 2:54

GoogleCodeExporter commented 9 years ago
Hello,

As I only read a YAML document for the moment, I don't have to duplicate any
YAML::Node, and I used the same fix as you in my own source tree. Thank you for 
the
correction!

Original comment by paul.mor...@gmail.com on 22 Sep 2008 at 10:51