From 78023ffca5d0e217654737b1317e228920c88c57 Mon Sep 17 00:00:00 2001 From: victorberdugo1 Date: Mon, 9 Mar 2026 11:50:19 +0000 Subject: [PATCH] Fix memory leak in LoadGLTF when model has no bones (#5629) Co-authored-by: Victor --- src/rmodels.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/rmodels.c b/src/rmodels.c index 0dd4f0634..3da1c0be7 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -5511,8 +5511,10 @@ static Model LoadGLTF(const char *fileName) if (dracoCompression) { - return model; TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to load glTF data", fileName); + cgltf_free(data); + UnloadFileData(fileData); + return model; } TRACELOG(LOG_DEBUG, " > Primitives (triangles only) count based on hierarchy : %i", primitivesCount); @@ -6334,6 +6336,14 @@ static Model LoadGLTF(const char *fileName) for (int j = 0; j < model.skeleton.boneCount; j++) model.boneMatrices[j] = MatrixIdentity(); //---------------------------------------------------------------------------------------------------- + if (model.skeleton.boneCount == 0) + { + RL_FREE(model.currentPose); + RL_FREE(model.boneMatrices); + model.currentPose = NULL; + model.boneMatrices = NULL; + } + // Free all cgltf loaded data cgltf_free(data); }