Skip to content

fix a memory leak, add asan / ubsan support to the cmake configuration#117

Merged
pelesh merged 5 commits into
ORNL:developfrom
superwhiskers:develop
May 30, 2025
Merged

fix a memory leak, add asan / ubsan support to the cmake configuration#117
pelesh merged 5 commits into
ORNL:developfrom
superwhiskers:develop

Conversation

@superwhiskers

Copy link
Copy Markdown
Collaborator

as the title says

…port to the cmake build, and fix a memory leak in `DistributedGeneratorTest`

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this. I made some optional suggestions.

Comment thread CMakeLists.txt
Comment on lines +40 to +55
# Enable the address sanitizer
option(GRIDKIT_ENABLE_ASAN "Enable the address sanitizer" OFF)

if(GRIDKIT_ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
endif()

# Enable the undefined behavior sanitizer
option(GRIDKIT_ENABLE_UBSAN "Enable the undefined behavior sanitizer" OFF)

if(GRIDKIT_ENABLE_UBSAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined")
endif()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making these flags part of an interface target, then link that target to GridKit libraries.

When we are at it, we could add a "developer mode" compiler flags that include -Wall -Wextra -Wconversion -pedantic.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

users may want to enable address sanitizer or ubsan independent of the target, so i don't think it's worthwhile to do that. however, i have added those compile flags you suggested to the default list of compile flags and fixed all warnings resulting from them in the current tree

@pelesh pelesh requested a review from nkoukpaizan May 30, 2025 15:31
@pelesh pelesh added bug Something isn't working development Features/Tools related to development of GridKit, rather than use as a library. cmake labels May 30, 2025
Comment thread examples/PowerElectronics/DistributedGeneratorTest/DGTest.cpp Outdated

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@pelesh pelesh merged commit 1303aa1 into ORNL:develop May 30, 2025
2 of 3 checks passed
WiktoriaZielinskaORNL pushed a commit that referenced this pull request Jul 23, 2025
#117)

* add `.editorconfig`, add undefined behavior and address sanitizer support to the cmake build, and fix a memory leak in `DistributedGeneratorTest`

* swap the heap allocated `DistributedGenerator` for one on the stack

* add warnings by default and fix warnings resulting from our code so that it builds cleanly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cmake development Features/Tools related to development of GridKit, rather than use as a library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants