Multiple memory leak defects #120767

Open
opened 2024-04-18 05:31:47 +02:00 by Yin_Lu_Ming · 19 comments

Dear Blender developers,

I have identified a memory leak defect in the latest version of Blender. The detailed path of the defect is as follows:

1.In the file /blender/extern/mantaflow/helper/util/simpleimage.cpp, a pointer variable named "pic" is defined on line 155, and a dynamic memory region is allocated using the new operator. If the if statement on line 159 returns true, the program returns on line 162 without executing the release operation on the dynamic memory region pointed to by "pic" on line 203. This constitutes a memory leak defect, as illustrated in the diagram below:
https://github.com/LuMingYinDetect/blender_defects/blob/main/blender_4.png

Dear Blender developers, I have identified a memory leak defect in the latest version of Blender. The detailed path of the defect is as follows: 1.In the file /blender/extern/mantaflow/helper/util/simpleimage.cpp, a pointer variable named "pic" is defined on line 155, and a dynamic memory region is allocated using the new operator. If the if statement on line 159 returns true, the program returns on line 162 without executing the release operation on the dynamic memory region pointed to by "pic" on line 203. This constitutes a memory leak defect, as illustrated in the diagram below: https://github.com/LuMingYinDetect/blender_defects/blob/main/blender_4.png
Yin_Lu_Ming added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2024-04-18 05:31:48 +02:00
Member

Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅

Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅
Author

Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅

I apologize for any inconvenience caused! I have uploaded the HTML file containing all memory leak defects from the report for your reference!

> Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅 I apologize for any inconvenience caused! I have uploaded the HTML file containing all memory leak defects from the report for your reference!
Author

Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅

Hello, in addition to the memory leak defect discovered earlier, I have found a new memory leak defect. Here are the details:

There is a memory leak defect at line 352 in the file /blender/source/blender/blentranslation/msgfmt/msgfmt.cc.

At line 292 of the file, a pointer variable named 'msgs_memarena' is defined, and a dynamic memory area is allocated through the function 'BLI_memarena_new'. When the 'if' statement at line 350 returns true, the program will return at line 352 without executing the release operation on the dynamic memory area pointed to by 'msgs_memarena' at line 438, thereby causing a memory leak defect, as shown in the attached image.

> Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅 Hello, in addition to the memory leak defect discovered earlier, I have found a new memory leak defect. Here are the details: There is a memory leak defect at line 352 in the file /blender/source/blender/blentranslation/msgfmt/msgfmt.cc. At line 292 of the file, a pointer variable named 'msgs_memarena' is defined, and a dynamic memory area is allocated through the function 'BLI_memarena_new'. When the 'if' statement at line 350 returns true, the program will return at line 352 without executing the release operation on the dynamic memory area pointed to by 'msgs_memarena' at line 438, thereby causing a memory leak defect, as shown in the attached image.
Yin_Lu_Ming changed title from There is a memory leak defect on line 162 of the file /blender/extern/mantaflow/helper/util/simpleimage.cpp. to Multiple memory leak defects 2024-04-18 09:39:45 +02:00
Author

Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅

Details of another newly discovered defect:

There is a memory leak defect at line 564 in the file /blender/source/blender/editors/object/object_bake.cc.

1.At line 559 of /blender/source/blender/editors/object/object_bake.cc, a pointer named 'bkr' is defined, and a dynamic memory area is allocated using the 'MEM_cnew' operator. When the 'if' statement at line 562 returns true, the program will return at line 564. During this process, the dynamic memory area pointed to by 'bkr' is neither used for data at line 574 nor released, as shown in the attached image.

> Hi, thanks for finding the memory leak. But could you mention all of these in single report. I think creating new report for each case will just increase the noise 😅 Details of another newly discovered defect: There is a memory leak defect at line 564 in the file /blender/source/blender/editors/object/object_bake.cc. 1.At line 559 of /blender/source/blender/editors/object/object_bake.cc, a pointer named 'bkr' is defined, and a dynamic memory area is allocated using the 'MEM_cnew' operator. When the 'if' statement at line 562 returns true, the program will return at line 564. During this process, the dynamic memory area pointed to by 'bkr' is neither used for data at line 574 nor released, as shown in the attached image.
Iliya Katushenock added the
Interest
Video Sequencer
Interest
Modeling
labels 2024-04-18 10:18:06 +02:00
Member

There is a memory leak defect at line 564 in the file /blender/source/blender/editors/object/object_bake.cc.

Maybe we can use unique_ptr in this case. I don't build with bake options (building is super slow on my laptop) so can't really check this :/

There is a memory leak defect at line 352 in the file /blender/source/blender/blentranslation/msgfmt/msgfmt.cc.

I think this is valid case. Memory only freed at the end of make() so returning early would indeed cause the leak.

I'm not sure about the other cases mentioned in html file (hard to read them atm).

> There is a memory leak defect at line 564 in the file /blender/source/blender/editors/object/object_bake.cc. Maybe we can use unique_ptr in this case. I don't build with bake options (building is super slow on my laptop) so can't really check this :/ > There is a memory leak defect at line 352 in the file /blender/source/blender/blentranslation/msgfmt/msgfmt.cc. I think this is valid case. Memory only freed at the end of make() so returning early would indeed cause the leak. I'm not sure about the other cases mentioned in html file (hard to read them atm).
Member

Don't know where exactly the leak is happening in uiTemplateMarker from clip_buttons.cc. Can you explain?

Don't know where exactly the leak is happening in `uiTemplateMarker` from `clip_buttons.cc`. Can you explain?
Member

Re: leak in sequencer_preview.cc, we could move the allocation of audiojob after if/else condition

Re: leak in `sequencer_preview.cc`, we could move the allocation of `audiojob` after if/else condition
Member

Can confirm the possible leak in alloc_proxy_output_ffmpeg from indexer.cc. Need to free memory when condition of BLI_file_ensure_parent_dir_exists is true.

Can confirm the possible leak in `alloc_proxy_output_ffmpeg` from `indexer.cc`. Need to free memory when condition of `BLI_file_ensure_parent_dir_exists` is true.
Member

Can confirm in simpleimage.cpp but not sure about the Cache.cpp
Marking this as confirmed since most of the cases are straightforward to check.

Can confirm in `simpleimage.cpp` but not sure about the `Cache.cpp` Marking this as confirmed since most of the cases are straightforward to check.
Pratik Borhade added
Status
Confirmed
and removed
Status
Needs Triage
labels 2024-04-24 07:36:08 +02:00
Member

but not sure about the Cache.cpp

Anyways, @ChengduLittleA already created PR for this !120766

> but not sure about the Cache.cpp Anyways, @ChengduLittleA already created PR for this !120766
Author

Don't know where exactly the leak is happening in uiTemplateMarker from clip_buttons.cc. Can you explain?

Regarding the memory leak present in the clip_buttons.cc file, you can refer to the description below.

1.In the file /blender/source/blender/editors/space_clip/clip_buttons.cc, a pointer variable named "cb" is defined on line 408, and a dynamic memory region is allocated using MEM_cnew. If the if statement on line 417 returns false, the program executes the else branch on line 444. If the if statement on line 449 returns true, the program returns on line 465. During this process, the dynamic memory region pointed to by "cb" is not deallocated, constituting a memory leak defect, as illustrated in the diagram below:
https://github.com/LuMingYinDetect/blender_defects/blob/main/blender_3.png

> Don't know where exactly the leak is happening in `uiTemplateMarker` from `clip_buttons.cc`. Can you explain? Regarding the memory leak present in the clip_buttons.cc file, you can refer to the description below. 1.In the file /blender/source/blender/editors/space_clip/clip_buttons.cc, a pointer variable named "cb" is defined on line 408, and a dynamic memory region is allocated using MEM_cnew. If the if statement on line 417 returns false, the program executes the else branch on line 444. If the if statement on line 449 returns true, the program returns on line 465. During this process, the dynamic memory region pointed to by "cb" is not deallocated, constituting a memory leak defect, as illustrated in the diagram below: https://github.com/LuMingYinDetect/blender_defects/blob/main/blender_3.png
Member

Yes thanks, can confirm the leak when track is locked.

Yes thanks, can confirm the leak when track is locked.
Member

I think we can close this one now?

I think we can close this one now?

@ChengduLittleA Not yet. Items 3, 4, 7, and 8 from https://github.com/LuMingYinDetect/blender_defects/tree/main are still pending.

@ChengduLittleA Not yet. Items 3, 4, 7, and 8 from https://github.com/LuMingYinDetect/blender_defects/tree/main are still pending.
Member

@deadpin I'll take care of those.

@deadpin I'll take care of those.
Member

Issue 4 is external (mantaflow), and the thing in issue 7 is that the program will terminate anyway so not much need to manually free those since there are a lot of early return paths.

Issue 4 is external (mantaflow), and the thing in issue 7 is that the program will terminate anyway so not much need to manually free those since there are a lot of early return paths.

Yeah, 7 would be low prio since that's really just a build-time tool. It's not included in our releases and, as you say, the process is on its way to exiting anyhow.

4 is effectively us. Upstream is no longer updating and we will forever remain on whatever is in extern so I'd say we can do the small fix for it. I'm not sure what would trigger that code path for us to be fair though.

Yeah, 7 would be low prio since that's really just a build-time tool. It's not included in our releases and, as you say, the process is on its way to exiting anyhow. 4 is effectively us. Upstream is no longer updating and we will forever remain on whatever is in `extern` so I'd say we can do the small fix for it. I'm not sure what would trigger that code path for us to be fair though.
Member

@deadpin I see. I'll make the mantaflow fix :D

@deadpin I see. I'll make the mantaflow fix :D
Member

Thanks @ChengduLittleA for handling rest cases :)

Thanks @ChengduLittleA for handling rest cases :)
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120767
No description provided.