Skip to content

[rmodels] Fix memory leak in UnloadModel() - #5907

Merged
raysan5 merged 1 commit into
raysan5:masterfrom
LuisR385:fix-unloadmodel-leak
Jun 4, 2026
Merged

[rmodels] Fix memory leak in UnloadModel()#5907
raysan5 merged 1 commit into
raysan5:masterfrom
LuisR385:fix-unloadmodel-leak

Conversation

@LuisR385

@LuisR385 LuisR385 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Description

There is a memory leak in UnloadModel() when loading and unloading 3D models with bones (skinned models).
LoadModel() allocates memory for model.currentPose and model.boneMatrices, but UnloadModel() does not free them.

Scope of leak

Tested with a GLB model containing 43 bones on raylib 6.0 (Windows / Visual Studio).
Leak sizes reported by Visual Studio exactly match the bone allocations:

  • 43 * sizeof(Transform) = 1720 bytes
  • 43 * sizeof(Matrix) = 2752 bytes

Solution

Added RL_FREE(model.currentPose); and RL_FREE(model.boneMatrices); inside UnloadModel() right before the TRACELOG.

The RL_FREE macro safely checks for NULL, so this will not cause any issues or crashes for non-animated models (models without bones).

@LuisR385 LuisR385 changed the title Fix memory leak in UnloadModel() [rmodels] Fix memory leak in UnloadModel() Jun 4, 2026
@raysan5
raysan5 merged commit fd79b81 into raysan5:master Jun 4, 2026
@raysan5

raysan5 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

@LuisR385 thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants