Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Invalid free/delete error in Boost.Test with minimal test case on Boost 1.85

Open
#419 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp, linux
Domain
testing-qa

Research direction

Reproduce the minimal test case with Boost.Test 1.85 under Valgrind, then inspect the static initialization and destruction paths shown in unit_test_parameters.ipp and test_instrument.cpp. Confirm the invalid free occurs at process exit and document or fix the relevant lifetime issue so the test exits without the Valgrind error.

Written by the indexing model from the issue text.

Description

I encountered an invalid free/delete error when running a minimal test case using Boost.Test with Boost 1.85. Below is the code and the error message from Valgrind.

Minimal Test Case:

#define BOOST_TEST_MODULE MinimalTest
#include <boost/test/included/unit_test.hpp>

BOOST_AUTO_TEST_CASE(minimal_test)
{
    BOOST_CHECK_EQUAL(1, 1);
}

Error Message from Valgrind:

==49727== Invalid free() / delete / delete[] / realloc()
==49727== at 0x484668F: operator delete(void*) (vg_replace_malloc.c:1131)
==49727== by 0x4CD467F: __cxa_finalize (cxa_finalize.c:82)
==49727== by 0x487CD96: ??? (in /usr/local/lib/libboost_unit_test_framework.so.1.85.0)
==49727== by 0x40010F1: _dl_call_fini (dl-call_fini.c:43)
==49727== by 0x40050AD: _dl_fini (dl-fini.c:114)
==49727== by 0x4CD4BB0: __run_exit_handlers (exit.c:108)
==49727== by 0x4CD4C7D: exit (exit.c:138)
==49727== by 0x4CBC08E: (below main) (libc_start_call_main.h:74)
==49727== Address 0x4e957c0 is 0 bytes inside a block of size 18 free'd
==49727== at 0x4846B81: operator delete(void*, unsigned long) (vg_replace_malloc.c:1181)
==49727== by 0x487715: std::__new_allocator::deallocate(char*, unsigned long) (new_allocator.h:172)
==49727== by 0x45D40E: UnknownInlinedFun (allocator.h:208)
==49727== by 0x45D40E: UnknownInlinedFun (alloc_traits.h:513)
==49727== by 0x45D40E: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_destroy(unsigned long) (basic_string.h:294)
==49727== by 0x45BA33: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_dispose() (basic_string.h:288)
==49727== by 0x415A25: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::~basic_string() (basic_string.h:809)
==49727== by 0x4CD4BB0: __run_exit_handlers (exit.c:108)
==49727== by 0x4CD4C7D: exit (exit.c:138)
==49727== by 0x4CBC08E: (below main) (libc_start_call_main.h:74)
==49727== Block was alloc'd at
==49727== at 0x4842FB5: operator new(unsigned long) (vg_replace_malloc.c:487)
==49727== by 0x45BA87: std::__new_allocator::allocate(unsigned long, void const*) (new_allocator.h:151)
==49727== by 0x44539F: UnknownInlinedFun (allocator.h:196)
==49727== by 0x44539F: UnknownInlinedFun (alloc_traits.h:478)
==49727== by 0x44539F: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_S_allocate(std::allocator&, unsigned long) (basic_string.h:131)
==49727== by 0x4452D5: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_create(unsigned long&, unsigned long) (basic_string.tcc:159)
==49727== by 0x444F3B: void std::__cxx11::basic_string<char, std::char_traits, std::allocator >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) (basic_string.tcc:229)
==49727== by 0x4245A7: std::__cxx11::basic_string<char, std::char_traits, std::allocator >::basic_string<std::allocator >(char const*, std::allocator const&) (basic_string.h:654)
==49727== by 0x4A5C7A: __static_initialization_and_destruction_0() (unit_test_parameters.ipp:97)
==49727== by 0x4AF515: _GLOBAL__sub_I__ZN5boost9unit_test6output22compiler_log_formatter9log_startERSom (test_instrument.cpp:14)
==49727== by 0x4CBC1C3: call_init (libc-start.c:145)
==49727== by 0x4CBC1C3: __libc_start_main@@GLIBC_2.34 (libc-start.c:347)
==49727== by 0x40E944: (below main) (in /home/avatli/workspace/bull/hft-api/build/tests/test_instrument)

Steps to Reproduce:

  1. Create a minimal test case as shown above.
  2. Compile and link the test case using Boost.Test.
  3. Run the test with Valgrind to observe the error.

Additional Information:

  1. Boost version: 1.85
  2. Compiler: g++ (GCC) 14.1.1 20240620 (Red Hat 14.1.1-6)
  3. Operating System: Linux fedora 6.9.5-200.fc40.x86_64
Dominant language
C++
Stars
217
Forks
149
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/test

All issues in boostorg/test

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.