From 060eeec1c17f8e4af3f05322e027d666f7ea2289 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 22 Nov 2012 01:37:41 +0800 Subject: [PATCH] bugfix: reclaim thread stack explicitly by using detached threads Otherwise the VmData size will keep increasing in multi-threads mode. Although the increasing VmData size doesn't mean there is enormous memory leak, it does show that the thread stack is not handled properly when threads exit. --- djvu.c | 5 ++++- pdf.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/djvu.c b/djvu.c index a09e036b7..4a2a082e3 100644 --- a/djvu.c +++ b/djvu.c @@ -531,7 +531,10 @@ static int reflowPage(lua_State *L) { kctx->src = src; if (kctx->precache) { pthread_t rf_thread; - pthread_create(&rf_thread, NULL, k2pdfopt_reflow_bmp, (void*) kctx); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create(&rf_thread, &attr, k2pdfopt_reflow_bmp, (void*) kctx); } else { k2pdfopt_reflow_bmp(kctx); } diff --git a/pdf.c b/pdf.c index b8f35a68c..2673eb682 100644 --- a/pdf.c +++ b/pdf.c @@ -615,7 +615,10 @@ static int reflowPage(lua_State *L) { kctx->src = src; if (kctx->precache) { pthread_t rf_thread; - pthread_create( &rf_thread, NULL, k2pdfopt_reflow_bmp, (void*) kctx); + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + pthread_create( &rf_thread, &attr, k2pdfopt_reflow_bmp, (void*) kctx); } else { k2pdfopt_reflow_bmp(kctx); }