From 1da668d7d6742cefce6783e1fd46c19fd0be097b Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Tue, 29 Mar 2022 13:56:02 +0200 Subject: [PATCH] feat: Clean up resources on garbage collect --- src/lua_libpulse_glib/pulseaudio.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lua_libpulse_glib/pulseaudio.c b/src/lua_libpulse_glib/pulseaudio.c index fb86808..f023166 100644 --- a/src/lua_libpulse_glib/pulseaudio.c +++ b/src/lua_libpulse_glib/pulseaudio.c @@ -71,8 +71,20 @@ pulseaudio_new(lua_State* L) } -// TODO: Implement `__gc` meta method to free the inner `pa_glib_mainloop` +/** + * Free the PulseAudio object + */ +static int +pulseaudio__gc(lua_State* L) +{ + pulseaudio* pa = luaL_checkudata(L, 1, LUA_PULSEAUDIO); + pa_glib_mainloop_free(pa->mainloop); + return 0; +} + + static const struct luaL_Reg pulseaudio_mt [] = { + {"__gc", pulseaudio__gc}, {NULL, NULL} };