SDL_ttf: Fix memory leak when destroying text

From 4a8bda9197cc4d6fafd188bc9df6c7e8749a43a2 Mon Sep 17 00:00:00 2001
From: Mirko Covizzi <[EMAIL REDACTED]>
Date: Wed, 13 Nov 2024 19:20:11 +0100
Subject: [PATCH] Fix memory leak when destroying text

The engine's `DestroyText` function is
never called, as well as the frees for some
internal components.
This fixes memory leaks reported by some users.

Signed-off-by: Mirko Covizzi <mrkcvzz@gmail.com>
---
 src/SDL_ttf.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index 4951c04e..80024fe9 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -4863,6 +4863,18 @@ void TTF_DestroyText(TTF_Text *text)
         return;
     }
 
+    DestroyEngineText(text);
+
+    if (text->internal->ops) {
+        SDL_free(text->internal->ops);
+    }
+    if (text->internal->clusters) {
+        SDL_free(text->internal->clusters);
+    }
+    if (text->internal->layout->lines) {
+        SDL_free(text->internal->layout->lines);
+    }
+
     TTF_SetTextFont(text, NULL);
     SDL_DestroyProperties(text->internal->props);
     SDL_free(text->text);