BlueBrain / libsonata

A python and C++ interface to the SONATA format
https://libsonata.readthedocs.io/en/stable/
GNU Lesser General Public License v3.0
11 stars 12 forks source link

Double free() of NodePopulationProperties #352

Closed a-vartenkov closed 3 months ago

a-vartenkov commented 5 months ago

The following code:

#include <bbp/sonata/config.h>
int main()
{

    auto config = bbp::sonata::CircuitConfig::fromFile("network/network_config.json");
    auto list_nodes = config.listNodePopulations();
    for (auto &population_name : list_nodes)
    {
        auto snt_population = config.getNodePopulation(population_name); // Error here!
        std::cout << snt_population.size() << std::endl;
    }
}

used with files network.zip

gives an error "free(): invalid pointer" for ~NodePopulationProperties() Compiler: g++ 12.3.0

mgeplf commented 5 months ago

Thanks for the report; I'm having issues getting the reproduction to work:

clang++-17  -I/home/gevaert/src/libsonata/include -I/home/gevaert/src/libsonata/extlib/HighFive/include -I/usr/include/hdf5/serial -I/home/gevaert/src/libsonata/extlib/Catch2/single_include -std=gnu++14 -L`pwd`/build/  -lsonata -o double-free double-free.cpp 

And using valgrind:

(venv) gevaert@work ~/src/libsonata (master u=)$ LD_PRELOAD=`pwd`/build/libsonata.so valgrind --leak-check=full ./double-free                                                                                                                                                                                                                                          127
==29591== Memcheck, a memory error detector
==29591== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==29591== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==29591== Command: ./double-free
==29591==
1
==29591==
==29591== HEAP SUMMARY:
==29591==     in use at exit: 1,864 bytes in 3 blocks
==29591==   total heap usage: 4,033 allocs, 4,030 frees, 1,004,525 bytes allocated
==29591==
==29591== LEAK SUMMARY:
==29591==    definitely lost: 0 bytes in 0 blocks
==29591==    indirectly lost: 0 bytes in 0 blocks
==29591==      possibly lost: 0 bytes in 0 blocks
==29591==    still reachable: 1,864 bytes in 3 blocks
==29591==         suppressed: 0 bytes in 0 blocks
==29591== Reachable blocks (those to which a pointer was found) are not shown.
==29591== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==29591==
==29591== For lists of detected and suppressed errors, rerun with: -s
==29591== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Could you include the full g++ command you're using to build? Are you building the library with the same version of gcc?

mgeplf commented 3 months ago

I'm going to close this, as I can't replicate and there isn't a follow up.