# Valgrind memcheck

> **TL;DR**
> OS: Linux / WSL / macOS (10.12 or later)
>
>
>
> Project format: [CMake](quick-cmake-tutorial.html) / [Makefile](makefiles-support.html) / [compilation database](compilation-database.html) with [custom build targets](custom-build-targets.html) / [Gradle](gradle-support.html)
>
>
>
> Toolchain: local / [remote](remote-projects-support.html) / [WSL](how-to-use-wsl-development-environment-in-product.html) / [Docker](clion-toolchains-in-docker.html)

[Valgrind Memcheck](http://valgrind.org/docs/manual/mc-manual.html) is a tool that detects memory usage problems such as leaks, invalid memory access-s, incorrect memory releases, and undefined value references.

Valgrind integration in CLion works on Linux, macOS, and Windows with [WSL](how-to-use-wsl-development-environment-in-product.html) (refer to [Valgrind on WSL](#valgrind-wsl)).

Procedure: Configure Valgrind

1. [Install](http://valgrind.org/downloads/?src=www.discoversdk.com) Valgrind on your system.

> **Note:**
> If you are working with WSL, install Valgrind on your WSL instance (`sudo apt-get install valgrind`) and provide CLion with the path to the executable (see step 3).

2. In CLion, go to `Settings | Build, Execution, Deployment | Dynamic Analysis Tools | Valgrind`.

3. CLion will attempt to detect the Valgrind binary as set in system `PATH`.

In case of a non-standard Valgrind location, provide the path manually in the Valgrind executable field.

4. Specify [analysis options](http://valgrind.org/docs/manual/mc-manual.html#mc-manual.options) or use the default ones.

5. Optionally, configure the list of the [suppression files](http://valgrind.org/docs/manual/manual-core.html#manual-core.suppress).

For example, a suppression file can be used to turn off Valgrind checks for particular libraries.

![Valgrind settings](https://resources.jetbrains.com/help/img/idea/2026.2/cl_valgrindSettings.png)

Procedure: Configure Valgrind on WSL

1. In `Settings | Build, Execution, Deployment | Dynamic Analysis Tools | Valgrind`, provide the 'subsystem' path to Valgrind, which is `/usr/bin/valgrind` by default, instead of the actual Windows location of the Valgrind binary.

2. Activate a [CMake profile](cmake-profile.html) connected to the WSL toolchain.

For this, do one of the following:

* Set the WSL toolchain as default. This way, it will automatically connect to the default CMake profile: ![wsl toolchain set as default](https://resources.jetbrains.com/help/img/idea/2026.2/cl_wsl_deftoolchain.png)

* Create a separate CMake profile, connect it to the WSL toolchain, and select this profile in the configurations switcher: ![CMake profile for the WSL toolchain](https://resources.jetbrains.com/help/img/idea/2026.2/cl_wsl_cmakeprofile.png)

Procedure: Run targets

> **Note:**
> Make sure to run Valgrind on a build with debug information. Otherwise, the Valgrind report might be incomplete or inaccurate.

To run a target (application or test) with Valgrind Memcheck, do one of the following:

* Click the ![](https://resources.jetbrains.com/help/img/idea/2026.2/app.actions.execute.svg) gutter icon and select Run 'your_target_name' with Valgrind Memcheck option from the menu:

![cl_runValgrindGutter.png](https://resources.jetbrains.com/help/img/idea/2026.2/Debug](run-debug-configuration.html) configuration and call `Run | Run 'your_target_name' with Valgrind Memcheck` from the main menu or click the dedicated toolbar icon:

![Running Valgrind from the main toolbar](https://resources.jetbrains.com/help/img/idea/2026.2/cl_Valgrind_Run_icon.png)

If Valgrind was not configured previously, CLion will open the configuration dialog.

> **Tip:**
> Valgrind might not work correctly when run on a project with [Google sanitizers](google-sanitizers.html). CLion will warn you about that:
>
> ![Warning about Valgrind with Google Sanitizers](https://resources.jetbrains.com/help/img/idea/2026.2/cl_valgrind_sanitizers_warning.png)

Procedure: Explore results

* When the launch is finished, open the Valgrind tab in the Run tool window.

![Valgrind Memcheck output](https://resources.jetbrains.com/help/img/idea/2026.2/cl_valgrind_outputnew.png)

* The left-hand pane shows the list of all problems found by Valgrind Memcheck. Each entry includes the instruction pointer, problematic function name, and (if possible) the source file where the problem is located.

* In the right-hand pane, you can find full stack frame description and the corresponding code preview (when possible).

> **Tip:**
> Press `F4` (Windows), `⌘ ↓` (macOS), `F4` (IntelliJ IDEA Classic (macOS)), `F4` (macOS System Shortcuts), `F4` (XWin), `F4` (GNOME), `F4` (KDE), `F4` (Emacs), `F4` (Sublime Text), `F4` (Sublime Text (macOS)), `⌘ ↓` (Xcode), `F4` (Visual Studio), `⌘ ↓` (Visual Studio (macOS)), `F4` (ReSharper), `⌘ ↓` (ReSharper (macOS)), `F4` (QtCreator), `F4` (QtCreator (macOS)), `F4` (NetBeans), `F12` (Eclipse), `F3` (Eclipse (macOS)) to jump back to the source code.
>
>
>
> Use the context menu action to copy the warning data to clipboard:
>
>
>
> ![Valgrind view context actions](https://resources.jetbrains.com/help/img/idea/2026.2/cl_valgrind_view_actions.png)

Procedure: Export and import results

* To export the results, click the Export ![cl_valgrindexport_b.png](https://resources.jetbrains.com/help/img/idea/2026.2/cl_valgrindexport_b.png) icon in the left pane of the Valgrind tab and specify the destination XML file:

![Export Valgrind results](https://resources.jetbrains.com/help/img/idea/2026.2/cl_valgrind_export.png) Note that the Export button is unavailable during execution.

* To import the results, select `Run | Import Valgrind XML Results` from the main menu and choose the XML file to import from.

