google / google/googletest

[Bug]: MSVC - Assertion macro SUCCEED() leeds to a memory leak.

Open
#4,569 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

### Describe the issue

To secure my C++ applications under MSVC (V17.10.3), I like to use the functions of the extension "[CRT debug heap](https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-debug-heap-details#heap-state-reporting-functions)" from Microsoft. I want to ensure that my software does not leave any memory fragments on the heap. My tests therefore checks whether the heap state is identical before and after a test case.

In most cases, this works very well. However, if I use the assertion macro SUCCEED(), a memory leak is reported.

### Steps to reproduce the problem

Use the following test case:

```cpp
TEST(GoogleTest, TestSucceed)
{
// ---- store heap state ----
_CrtMemState s1, s2, s3;
_CrtMemCheckpoint(&s1);

// ---- TEST ----

// EXPECT_TRUE(true); // (1)
SUCCEED(); // (2)

// ---- compare heap state ----
_CrtMemCheckpoint(&s2);
bool hasMemoryLeaks = (0 != _CrtMemDifference(&s3, &s1, &s2));
if (hasMemoryLeaks)
{
_CrtMemDumpAllObjectsSince(&s1);
}
EXPECT_FALSE(hasMemoryLeaks);
}
```
The test ends successfully as long as I use the assertion `EXPECT_TRUE(true)` (marker **`(1)`**).
As soon as I use the macro `SUCCEED()` (marker **`(2)`**), a memory leak is reported at the end.

### What version of GoogleTest are you using?

GoogleTest v1.14.0
commit f8d7d77c06936315286eb55f8de22cd23c188571

### What operating system and version are you using?

Microsoft Windows 11
Version 23H2 (Build 22631.3447)

### What compiler and version are you using?

Microsoft Visual Studio Professional 2022 (64-bit)
Current Version 17.10.3

### What build system are you using?

msbuild --version
MSBuild-Version 17.10.4+10fbfbf2e für .NET Framework
17.10.4.21802

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue on Windows 11 with MSVC 17.10.3 using the provided test and CRT debug heap checks. Compare the heap results for EXPECT_TRUE(true) and SUCCEED(), then trace the SUCCEED() assertion path. Done means the provided test no longer reports a memory leak when SUCCEED() is used.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.