Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E2F3F9D31 for ; Sat, 25 May 2013 15:21:23 +0000 (UTC) Received: (qmail 65028 invoked by uid 500); 25 May 2013 15:21:23 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 64771 invoked by uid 500); 25 May 2013 15:21:23 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 64760 invoked by uid 99); 25 May 2013 15:21:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 May 2013 15:21:23 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sindhi.for@gmail.com designates 209.85.223.182 as permitted sender) Received: from [209.85.223.182] (HELO mail-ie0-f182.google.com) (209.85.223.182) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 May 2013 15:21:18 +0000 Received: by mail-ie0-f182.google.com with SMTP id a14so14915909iee.41 for ; Sat, 25 May 2013 08:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Eyvr12uXCSa8B1laFEBL0u8tI9TlFxKhOh6LsqAlNqQ=; b=cwoDH71/Xz803aHHem27bpi+25FfsqBATwcRWnAGhw5rmbP2Ul3UIr/a+Pt6bcq1MV YG0MUHTd+F7SOCq7BXOfvsByJTpGL4a197VZEcNPazuRiCi1Gndl9o7ufXTmEKSGi7YV XQkUa85PqEyx5xIZ9H5o+dbWynA6Kj1hZBm4D7r5yfmElHcmmX9nvqFlEnqR6TMKHZUB Jd5u/PEuqE3ILv9Yi2rLAeTCS4EkN4H7/5ratH59Po//bTBbtn/gQCaNIKgMTCjYqNOb CTaUp5bBaDOvNUi22ohtOSlHu0CYqHtC2ZHWp17ubKsdOvmYMjbyccb9K85xwathXQ60 LxaA== MIME-Version: 1.0 X-Received: by 10.50.25.4 with SMTP id y4mr1740257igf.111.1369495257780; Sat, 25 May 2013 08:20:57 -0700 (PDT) Received: by 10.64.22.193 with HTTP; Sat, 25 May 2013 08:20:57 -0700 (PDT) In-Reply-To: References: Date: Sat, 25 May 2013 20:50:57 +0530 Message-ID: Subject: Re: Apache: Create server config only once From: Sindhi Sindhi To: modules-dev@httpd.apache.org Content-Type: multipart/alternative; boundary=047d7bd75e1e5c9a2404dd8c7636 X-Virus-Checked: Checked by ClamAV on apache.org --047d7bd75e1e5c9a2404dd8c7636 Content-Type: text/plain; charset=ISO-8859-1 I tried to make the class MyFilterInit a Singleton class, but when CreateServerConfig is called the second time, MyFilterInit constructor is called is called second time, and here I see that the static instance of MyFilterInit in the second call is set to NULL, which should have ideally been a address that was set by the previous call. Any help is highly appreciated. On Sat, May 25, 2013 at 6:52 PM, Sindhi Sindhi wrote: > Hi, > > I see that the create_server_config callback is called twice for every > Apache server startup. I want to do a lot of initialization in this > callback and allocations in this function are meant to be long lived. And > these buffers are very huge, so I want to ensure these initializations are > done only once per server start. As of now I'm trying to do the following - > > typedef struct > { > int bEnabled; // Enable or disable the module. > MyFilterInit* myFilterInitObj; // A class that has methods to do all huge > initializations > bool serverConfigured; > } MyFilterConfig; > > static int serverConfigHit = 0; > > static void* CreateServerConfig(apr_pool_t* pool, server_rec* virtServer) { > MyFilterConfig *pExistingConfig = (MyFilterConfig *) > ap_get_module_config (virtServer, &tag_filter_module); > > if (serverConfigHit == 0) { > MyFilterConfig *pConfig = (MyFilterConfig *) apr_pcalloc (pool, sizeof > *pConfig); > pConfig->myFilterInitObj = new MyFilterInit(); // This does all the huge > initializations > serverConfigHit = serverConfigHit +1; > return pConfig; > } > return pExistingConfig; > } > > But I see an issue here. The second time when CreateServerConfig is > called, > 1. pExistingConfig is not having the address which was set during the > first call to CreateServerConfig > 2. serverConfigHit is zero. > > Which means when CreateServerConfig was called first time, all the > initializations I made is not recorded by the server. Which means all the > allocations I made in the first call using malloc/new will result in a > memory leak. > > Kindly advice how do I ensure that my initializations are performed only > once. > > Thanks > --047d7bd75e1e5c9a2404dd8c7636--