How to find exact line of code of memory leaks in Clion c++ using MacOS Monterey 12.0.1 leaks?

1.8k Views Asked by At

I am using Clion and I want to find a way to find memory leaks on Mac M1. Valgrind is not supported yet.

Let's take this simple code with memory leak:

// Program with memory leak

#include <cstdlib>

using namespace std;

// function with memory leak
void func_to_show_mem_leak()
{
    int* ptr = new int(5);

    // body

    // return without deallocating ptr
    return;
}

// driver code
int main()
{

    // Call the function
    // to get the memory leak
    func_to_show_mem_leak();

    system("leaks SimpleMemoryLeak");
    return 0;
}

I've tried using leaks :

leaks *NameOfProccess*

and I am getting this output:

Process 70526 is not debuggable. Due to security restrictions, leaks can only show or save contents of readonly memory of restricted processes.

Process:         SimpleMemoryLeak [70526]
Path:            /Users/USER/Documents/*/SimpleMemoryLeak
Load Address:    0x100ec8000
Identifier:      SimpleMemoryLeak
Version:         ???
Code Type:       ARM64
Parent Process:  clion [39550]

Date/Time:       2021-12-05 23:32:52.942 +0100
Launch Time:     2021-12-05 23:32:52.307 +0100
OS Version:      macOS 12.0.1 (21A559)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         945K
Physical footprint (peak):  945K
----

leaks Report Version: 4.0
Process 70526: 208 nodes malloced for 12 KB
Process 70526: 1 leak for 16 total leaked bytes.

    1 (16 bytes) ROOT LEAK: 0x6000003ac030 [16]

Is there any way to get the exact line of code where malloc is located? Thanks!

0

There are 0 best solutions below