https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106949
Bug ID: 106949
Summary: Memory leak using VLA with -fsplit-stack
Product: gcc
Version: 11.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: iam at datacompboy dot ru
Target Milestone: ---
Created attachment 53575
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53575&action=edit
minimal repro case
Having a function with couple of VLA arrays enough to cause a memory leak.
If you run the function in a loop, memory leak only grows.
```
$ gcc -fsplit-stack -g b.c && valgrind ./a.out
==6861== HEAP SUMMARY:
==6861== in use at exit: 20,040 bytes in 2 blocks
==6861== total heap usage: 2 allocs, 0 frees, 20,040 bytes allocated
==6861==
==6861== LEAK SUMMARY:
==6861== definitely lost: 24 bytes in 1 blocks
==6861== indirectly lost: 20,016 bytes in 1 blocks
```
With a loop running function 10k times:
```
$ gcc -fsplit-stack -g c.c && valgrind ./a.out
==6931== HEAP SUMMARY:
==6931== in use at exit: 569,801,800 bytes in 32,162 blocks
==6931== total heap usage: 32,162 allocs, 0 frees, 569,801,800 bytes
allocated
==6931==
==6931== LEAK SUMMARY:
==6931== definitely lost: 385,944 bytes in 16,081 blocks
==6931== indirectly lost: 569,121,904 bytes in 16,072 blocks
==6931== possibly lost: 293,952 bytes in 9 blocks
```