Memory leak at debugger-agent.c (dotnet version - 11.0.100-rc.1.26420.103)
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
**Potential problem**
In `/src/runtime/src/mono/mono/component/debugger-agent.c` the variable `event_requests` is initialized twice. The first initialization is performed at line 792 via a call to `g_ptr_array_new`, and the second one is performed at line 808 inside the function `mono_init_debugger_agent_common` (line 1623). As a result, the memory allocated after the first initialization is lost, because the pointer to it is overwritten by the second assignment.
A similar issue exists with the variable `pending_assembly_loads` — it is first initialized at line 808 inside the function `mono_init_debugger_agent_common` (line 1625), and then re-initialized at line 810 via a call to `g_ptr_array_new`, which again leaks the previously allocated memory.
**Possible solution**
It is suggested to add checks in the relevant places (at lines 1623 and 810) to ensure that the variable has not been initialized yet before performing the assignment. It is also acceptable to add such checks in every place where the variables are initialized (lines 792, 810, 1623, and 1625).
Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.
Author A. Burlakov.
Contributor guide
Research direction
Start in /src/runtime/src/mono/mono/component/debugger-agent.c and inspect the initializations around lines 792, 808, and 810, including mono_init_debugger_agent_common around line 1623. Trace event_requests and pending_assembly_loads through each initialization. Done means neither pointer is overwritten after allocation, so the reported memory leaks are prevented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100