Skip to content

GeneralField memory leak(s) #1

@jsiwek

Description

@jsiwek

Should non-null return values from myXmlGetProp() in GeneralField.cpp be freed somewhere with xmlFree() ?

For example, this code:

#include <DataSeries/ExtentType.hpp>
#include <DataSeries/GeneralField.hpp>
#include <string>
#include <fstream>
#include <sstream>

int main(int argc, char** argv)
    {
    ExtentTypeLibrary log_types;
    ExtentType::Ptr log_type;
    ExtentSeries log_series;

    std::ifstream f("schema.xml");
    std::stringstream buf;
    buf << f.rdbuf();
    std::string schema = buf.str();

    log_type = log_types.registerTypePtr(schema);
    log_series.setType(log_type);

    GeneralField* gf = GeneralField::create(log_series, "t");

    delete gf;

    return 0;
    }

Where schema.xml is:

<ExtentType name="test" version="1.0" namespace="bro-ids.org">
    <field type="double" name="t" pack_relative="t" pack_scale="1e-6" print_format="%.6f" pack_scale_warn="no"/>
    <field type="variable32" name="id.orig_h" pack_unique="yes"/>
    <field type="int64" name="id.orig_p" />
    <field type="variable32" name="id.resp_h" pack_unique="yes"/>
    <field type="int64" name="id.resp_p" />
</ExtentType>
<!-- t : time -->
<!-- id.orig_h : addr -->
<!-- id.orig_p : port -->
<!-- id.resp_h : addr -->
<!-- id.resp_p : port --

Has valgrind report this leak:

5 bytes in 1 blocks are definitely lost in loss record 2 of 29
at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
by 0x5768B8D: xmlStrndup (xmlstring.c:45)
by 0x4D93695: myXmlGetProp(_xmlNode*, unsigned char const*) (GeneralField.cpp:522)
by 0x4D973C1: GF_Double::GF_Double(_xmlNode*, ExtentSeries&, std::string const&) (GeneralField.cpp:977)
by 0x4D9B391: GeneralField::create(_xmlNode*, ExtentSeries&, std::string const&) (GeneralField.cpp:1379)
by 0x403AA4: GeneralField::create(ExtentSeries&, std::string const&) (GeneralField.hpp:215)
by 0x4034E4: main (test.cc:21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions