Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1048 Memory leak in 3rd party library #1060

Merged
merged 16 commits into from
Mar 14, 2023
3 changes: 3 additions & 0 deletions .ci/docker/buildpack-arm64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ RUN apt update && \
ENV CC=aarch64-linux-gnu-gcc-5
ENV CXX=aarch64-linux-gnu-g++-5
ENV INDIGO_QEMU_BINARY=qemu-aarch64-static
ENV ASAN_OPTIONS=alloc_dealloc_mismatch=0
RUN echo $'leak:libfontconfig\nleak:libc\n' >> /opt/external.supp
ENV LSAN_OPTIONS=suppressions=/opt/external.supp

RUN cmake --version && \
aarch64-linux-gnu-gcc-5 --version && \
Expand Down
9 changes: 7 additions & 2 deletions .ci/docker/buildpack-centos7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ ARG GIT_VERSION=227
RUN yum install -y epel-release centos-release-scl
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
RUN yum update -y
RUN yum install -y devtoolset-${DEVTOOLSET_VERSION}-gcc-c++ devtoolset-${DEVTOOLSET_VERSION}-libasan-devel freetype-devel fontconfig-devel make python3 rh-git${GIT_VERSION}
RUN yum install -y devtoolset-${DEVTOOLSET_VERSION}-gcc-c++ devtoolset-${DEVTOOLSET_VERSION}-libasan-devel devtoolset-${DEVTOOLSET_VERSION}-liblsan-devel freetype-devel fontconfig-devel make python3 rh-git${GIT_VERSION}
RUN yum clean -y all
RUN echo $'leak:libfontconfig\nleak:libc\n' >> /opt/external.supp

# Enable the SCL for all bash scripts.
ENV MANPATH=/opt/rh/rh-git${GIT_VERSION}/root/usr/share/man:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/share/man \
X_SCLS="devtoolset-${DEVTOOLSET_VERSION} rh-git${GIT_VERSION}" \
PCP_DIR=/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root \
PATH=/opt/rh/rh-git${GIT_VERSION}/root/usr/bin:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
PKG_CONFIG_PATH=/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64/pkgconfig \
LD_LIBRARY_PATH=/opt/rh/httpd24/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64/dyninst:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib/dyninst:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib
LD_LIBRARY_PATH=/opt/rh/httpd24/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64/dyninst:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib/dyninst:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib64:/opt/rh/devtoolset-${DEVTOOLSET_VERSION}/root/usr/lib \
LSAN_OPTIONS=suppressions=/opt/external.supp \
ASAN_OPTIONS=alloc_dealloc_mismatch=0


RUN PIP_ONLY_BINARY="cmake" python3 -m pip install cmake

RUN cmake --version && \
Expand Down
10 changes: 5 additions & 5 deletions api/c/indigo-renderer/src/indigo_render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "indigo_renderer_internal.h"
#include "option_manager.h"

//#define INDIGO_DEBUG
// #define INDIGO_DEBUG

#ifdef INDIGO_DEBUG
#include <iostream>
Expand Down Expand Up @@ -488,18 +488,18 @@ CEXPORT int indigoRender(int object, int output)
if (IndigoBaseMolecule::is(obj))
{
if (obj.getBaseMolecule().isQueryMolecule())
rp.mol = std::make_unique<QueryMolecule>();
rp.mol.reset(new QueryMolecule());
else
rp.mol = std::make_unique<Molecule>();
rp.mol.reset(new Molecule());
rp.mol->clone_KeepIndices(self.getObject(object).getBaseMolecule());
rp.rmode = RENDER_MOL;
}
else if (IndigoBaseReaction::is(obj))
{
if (obj.getBaseReaction().isQueryReaction())
rp.rxn = std::make_unique<QueryReaction>();
rp.rxn.reset(new QueryReaction());
else
rp.rxn = std::make_unique<Reaction>();
rp.rxn.reset(new Reaction());
rp.rxn->clone(self.getObject(object).getBaseReaction(), 0, 0, 0);
rp.rmode = RENDER_RXN;
}
Expand Down
9 changes: 4 additions & 5 deletions api/c/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ project(indigo-api-unit-tests LANGUAGES CXX)

if (ENABLE_TESTS)
if(UNIX AND NOT APPLE)
# commented out due to memory leaks
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -g")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -g")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
endif()
set(DATA_PATH ${CMAKE_SOURCE_DIR}/data)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/common.h.in ${CMAKE_CURRENT_BINARY_DIR}/common.h)
Expand Down
9 changes: 4 additions & 5 deletions api/cpp/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ project(indigo-cpp-unit-tests LANGUAGES CXX)

if (ENABLE_TESTS)
if(UNIX AND NOT APPLE)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -g")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -g")
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
# set(CMAKE_CXX_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=leak -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
endif()
set(DATA_PATH ${CMAKE_SOURCE_DIR}/data)
file(GLOB_RECURSE ${PROJECT_NAME}_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp)
Expand Down
8 changes: 3 additions & 5 deletions core/indigo-core/common/base_cpp/string_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ int StringPool::_add(const char* str, int size)

if (idx >= _storage.size())
_storage.resize(idx + 1);
if (_storage.at(idx) == 0)
_storage.set(idx, new Array<char>());
if (size == -1 && str == 0)
throw Error("Internal error: size == -1 && str == 0");

if (size == -1)
size = strlen(str);
_storage.at(idx)->resize(size + 1);
_storage.at(idx).resize(size + 1);
if (str != 0 && size != 0)
memcpy(at(idx), str, size);
at(idx)[size] = 0;
Expand Down Expand Up @@ -77,12 +75,12 @@ void StringPool::remove(int idx)

char* StringPool::at(int idx)
{
return _storage[_pool[idx]]->ptr();
return _storage[_pool[idx]].ptr();
}

const char* StringPool::at(int idx) const
{
return _storage[_pool[idx]]->ptr();
return _storage[_pool[idx]].ptr();
}

int StringPool::size() const
Expand Down
4 changes: 2 additions & 2 deletions core/indigo-core/common/base_cpp/string_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#define __string_pool_h__

#include "base_cpp/auto_iter.h"
#include "base_cpp/obj_array.h"
#include "base_cpp/pool.h"
#include "base_cpp/ptr_array.h"

#ifdef _WIN32
#pragma warning(push)
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace indigo
int _add(const char* str, int size);

Pool<int> _pool;
PtrArray<Array<char>> _storage;
ObjArray<Array<char>> _storage;

private:
StringPool(const StringPool&); // no implicit copy
Expand Down
2 changes: 0 additions & 2 deletions core/indigo-core/molecule/molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ namespace indigo
{
public:
Molecule();
~Molecule() override;

Molecule& asMolecule() override;

void clear() override;
Expand Down
4 changes: 0 additions & 4 deletions core/indigo-core/molecule/src/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ Molecule::Molecule()
_ignore_bad_valence = false;
}

Molecule::~Molecule()
{
}

Molecule& Molecule::asMolecule()
{
return *this;
Expand Down
1 change: 0 additions & 1 deletion core/indigo-core/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ if (ENABLE_TESTS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize=leak -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address -fsanitize=leak")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1)
endif()
set(DATA_PATH ${CMAKE_SOURCE_DIR}/data)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/common.h.in ${CMAKE_CURRENT_BINARY_DIR}/common.h)
Expand Down
15 changes: 3 additions & 12 deletions core/render2d/src/render_cdxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,11 @@ void RenderParamCdxmlInterface::render(RenderParams& params)
void RenderParamCdxmlInterface::_renderRxns(RenderParams& params)
{
ReactionCdxmlSaver saver(*params.rOpt.output);

Array<BaseReaction*> rxns;

if (params.rxns.size() != 0)
for (int i = 0; i < params.rxns.size(); ++i)
rxns.push(params.rxns[i]);
else if (params.rxn.get() != 0)
rxns.push(params.rxn.get());

for (int rxn_ind = 0; rxn_ind < rxns.size(); rxn_ind++)
{
BaseReaction& rxn = (BaseReaction&)*rxns[rxn_ind];
saver.saveReaction(rxn);
}
saver.saveReaction(*params.rxns[i]);
else if (params.rxn)
saver.saveReaction(*params.rxn);
}

void RenderParamCdxmlInterface::_renderMols(RenderParams& params)
Expand Down
2 changes: 0 additions & 2 deletions core/render2d/src/render_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void RenderParams::clear()
relativeThickness = 1.0f;
bondLineWidthFactor = 1.0f;
rmode = RENDER_NONE;
mol.reset(nullptr);
rxn.reset(nullptr);
rOpt.clear();
cnvOpt.clear();
clearArrays();
Expand Down
9 changes: 2 additions & 7 deletions third_party/inchi/INCHI_BASE/src/runichi4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,21 +1324,16 @@ void FreeAllINChIArrays( PINChI2 *pINChI[INCHI_NUM],
int k;
for (k = 0; k < INCHI_NUM; k++)
{
int nk = num_components[k];

FreeINChIArrays( pINChI[k], pINChI_Aux[k], num_components[k] );

num_components[k] = 0;

if (nk && /* added check for nk: 2013-12-15 IPl */
pINChI[k])
if ( pINChI[k] )
{
inchi_free( pINChI[k] );
pINChI[k] = NULL;
}

if (nk && /* added check for nk: 2013-12-15 IPl */
pINChI_Aux[k])
if ( pINChI_Aux[k] )
{
inchi_free( pINChI_Aux[k] );
pINChI_Aux[k] = NULL;
Expand Down