Return-Path: Delivered-To: apmail-apr-cvs-archive@apr.apache.org Received: (qmail 74946 invoked by uid 500); 13 Jun 2001 01:35:49 -0000 Mailing-List: contact cvs-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: dev@apr.apache.org Delivered-To: mailing list cvs@apr.apache.org Received: (qmail 74935 invoked by uid 1103); 13 Jun 2001 01:35:48 -0000 Date: 13 Jun 2001 01:35:48 -0000 Message-ID: <20010613013548.74934.qmail@apache.org> From: dreid@apache.org To: apr-cvs@apache.org Subject: cvs commit: apr/memory/unix apr_sms.c dreid 01/06/12 18:35:48 Modified: memory/unix apr_sms.c Log: More cleanup... - fix a spelling mistake (whoops) - add a comment about why we call pre_destroy where we do for resets - make the child_cleanup calls more obvious by passing in the child rather than the whole sms structure Revision Changes Path 1.22 +17 -13 apr/memory/unix/apr_sms.c Index: apr_sms.c =================================================================== RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- apr_sms.c 2001/06/13 00:31:14 1.21 +++ apr_sms.c 2001/06/13 01:35:47 1.22 @@ -120,7 +120,7 @@ if (sms->realloc_fn) return sms->realloc_fn(sms, mem, size); - /* XXX - shoulod we free the block passed in ??? */ + /* XXX - should we free the block passed in ??? */ return NULL; } @@ -310,17 +310,21 @@ */ static void apr_sms_do_child_cleanups(apr_sms_t *sms) { - if (!sms) - return; - - sms = sms->child; while (sms) { - apr_sms_do_child_cleanups(sms); + apr_sms_do_child_cleanups(sms->child); apr_sms_do_cleanups(sms->cleanups); - + /* + * We assume that all of our children & their siblings are created + * from memory we've allocated, and as we're about to nuke it all + * we need to run the pre_destroy so things like locks can be + * cleaned up so we don't leak. + * However, we aren't going to call destroy on a reset as we're about + * to nuke them when we do the reset. This is why all "leakable" + * items created in an sms module MUST be cleaned up in the + * pre_destroy not the destroy. + */ if (sms->pre_destroy_fn != NULL) sms->pre_destroy_fn(sms); - sms = sms->sibling; } } @@ -338,7 +342,7 @@ * Run the cleanups of all child memory systems _including_ * the accounting memory system. */ - apr_sms_do_child_cleanups(sms); + apr_sms_do_child_cleanups(sms->child); /* Run all cleanups, the memory will be freed by the reset */ apr_sms_do_cleanups(sms->cleanups); @@ -377,9 +381,10 @@ /* * Run the cleanups of all child memory systems _including_ * the accounting memory system. + * This also does the pre_destroy functions in the children. */ - apr_sms_do_child_cleanups(sms); - + apr_sms_do_child_cleanups(sms->child); + /* Run all cleanups, the memory will be freed by the destroy */ apr_sms_do_cleanups(sms->cleanups); } @@ -392,8 +397,7 @@ * child list (we will explicitly destroy it later in this block). */ if (child->sibling != NULL) - child->sibling->ref = - child->ref; + child->sibling->ref = child->ref; *child->ref = child->sibling;