From bebc9eb58b417e1da64853e1451d058e9db1cee7 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 24 Aug 2022 17:12:41 +0000 Subject: [PATCH] Memory improvements FossilOrigin-Name: 74d721f05bd0cb5fd53a5fff34258113afc9087f2083688f733bc3fe5b32e323 --- src/base_page.c | 8 ++++---- src/main.c | 5 +++-- src/notifications.c | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/base_page.c b/src/base_page.c index 390406c..420cb1d 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -70,16 +70,16 @@ void render_base_page(struct base_page* page, FCGX_Request* req, struct session* PERL_STACK_INIT; if (page->session) - mXPUSHs(newRV_inc((SV*)page->session)); + mXPUSHs(newRV_noinc((SV*)page->session)); else - mXPUSHs(newRV_inc((SV*)perlify_session(ssn))); - XPUSHs(newRV_inc((SV*)template_files)); + mXPUSHs(newRV_noinc((SV*)perlify_session(ssn))); + XPUSHs(newRV_noinc((SV*)template_files)); XPUSHs(sv_2mortal(newSVpv(page->content, 0))); if (notifs && notifs_len) { AV* notifs_av = perlify_notifications(notifs, notifs_len); - XPUSHs(sv_2mortal(newRV_inc((SV*)notifs_av))); + mXPUSHs(newRV_inc((SV*)notifs_av)); } else XPUSHs(&PL_sv_undef); diff --git a/src/main.c b/src/main.c index 2a58434..801b6aa 100644 --- a/src/main.c +++ b/src/main.c @@ -55,9 +55,10 @@ static void xs_init (pTHX); EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); #ifdef DEBUG +static int quit = 0; static void exit_treebird(PATH_ARGS) { - exit(0); + quit = 1; } #endif @@ -213,7 +214,7 @@ static void* threaded_fcgi_start(void* arg) #else void cgi_start(mastodont_t* api) { - while (FCGI_Accept() >= 0) + while (FCGI_Accept() >= 0 && quit == 0) { application(api, NULL); } diff --git a/src/notifications.c b/src/notifications.c index e5bdf9d..51f4166 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -111,11 +111,11 @@ void content_notifications_compact(PATH_ARGS) PERL_STACK_INIT; HV* session_hv = perlify_session(ssn); - XPUSHs(newRV_noinc((SV*)session_hv)); + mXPUSHs(newRV_noinc((SV*)session_hv)); XPUSHs(newRV_noinc((SV*)template_files)); if (notifs) - XPUSHs(newRV_noinc((SV*)perlify_notifications(notifs, notifs_len))); - + mXPUSHs(newRV_noinc((SV*)perlify_notifications(notifs, notifs_len))); + PERL_STACK_SCALAR_CALL("notifications::embed_notifications"); page = PERL_GET_STACK_EXIT; @@ -124,6 +124,7 @@ void content_notifications_compact(PATH_ARGS) mastodont_storage_cleanup(&storage); mstdnt_cleanup_notifications(notifs, notifs_len); + Safefree(page); } void content_notifications_clear(PATH_ARGS)