httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 张 臻博 <laron...@hotmail.com>
Subject RE: Whitescreens when using a dir-conf merge function
Date Thu, 08 Feb 2007 11:03:18 GMT
Hi,

I have gone through your code quickly. It seems there is some problem in 
your merge function:
>    rbl_handler*    from_rbl_handler;
>    rbl_handler*    to_rbl_handler;
here you haven't pcalloc the memory for it. However late you pass these 
pointers to the function:
>static void apr_copy_rbhlcpy(apr_pool_t* p, rbl_handler* 
>from_rbl_handler,
>rbl_handler* to_rbl_handler)
In this function you use pointer to accept parmaters. Should you use double 
pointer?(e.g.rbl_handler* from_rbl_handler). My suggestion is that you 
allocate the memory in your merge function and then in apr_copy_rbhlcpy try 
to use double pointer. 

I am not so sure whether it is the reason. but you can have a try.

br
frankie



>From: "David Wortham" <djwortham@gmail.com>
>Reply-To: modules-dev@httpd.apache.org
>To: modules-dev@httpd.apache.org
>Subject: Whitescreens when using a dir-conf merge function
>Date: Wed, 7 Feb 2007 14:19:26 -0700
>
>Hi all,
>   I'm adding a merge function (for use with directory-based 
>configuration
>and server-based configuration).
>
>When I finished the function, I noticed that it was causing 
>whitescreens
>(empty responses).
>
>As you can see below, I allocate memory via 'apr_pcalloc' and then 
>I:
>(1) loop through each existing 'rbl_handler' from the parentdir_cfg, 
>copying
>it to the new_dir_cfg, then
>(2) loop through each existing 'rbl_handler' from the subdir_cfg, 
>copying it
>to the new_dir_cfg.
>
>With my current directive configuration, there are no directives to 
>copy (so
>the loops fail the first conditional and are never entered), but 
>Apache
>whitescreens nonetheless.  There are no errors or warnings on 
>compile.
>
>Am I allocating memory correctly, or perhaps my concept of merging 
>(and when
>the merge function is called) is bad?
>
>
>
>The relevant code follows:
>
>/* start code snippet */
>
>// since memcpy was causing errors, I coded this function to do the 
>same
>(only much slower)
>static void apr_copy_rbhlcpy(apr_pool_t* p, rbl_handler* 
>from_rbl_handler,
>rbl_handler* to_rbl_handler)
>{
>    if (from_rbl_handler)
>    {
>        to_rbl_handler->category_bs     = 
>from_rbl_handler->category_bs;
>        to_rbl_handler->score_lb        = 
>from_rbl_handler->score_lb;
>        to_rbl_handler->score_ub        = 
>from_rbl_handler->score_ub;
>        to_rbl_handler->days_lb         = from_rbl_handler->days_lb;
>        to_rbl_handler->days_ub         = from_rbl_handler->days_ub;
>        to_rbl_handler->verb_bs         = from_rbl_handler->verb_bs;
>        to_rbl_handler->action_string   =
>(from_rbl_handler->action_string)?apr_pstrdup(p,
>from_rbl_handler->action_string):NULL;
>    }
>}
>
>// the merge function
>static void* my_merge_dir_conf (apr_pool_t* p, void* parent_dirv, 
>void*
>subdirv)
>{
>    httpbl_dir_cfg* parent_dir              = (httpbl_dir_cfg *)
>parent_dirv;
>    httpbl_dir_cfg* subdir                  = (httpbl_dir_cfg *) 
>subdirv;
>    httpbl_dir_cfg* new_dir_cfg             = (httpbl_dir_cfg *) 
>apr_palloc
>(p, sizeof(httpbl_dir_cfg));
>
>    int             i                       = 0; // i = the
>num_of_rbl_handlers already written in the new_dir_cfg array
>    int             j                       = 0; // j = the
>num_of_rbl_handlers read from from_rbl_handler
>    new_dir_cfg->default_action             = 
>subdir->default_action;
>    new_dir_cfg->is_404_recording_enabled   =
>subdir->is_404_recording_enabled;
>    new_dir_cfg->is_exempt                  = subdir->is_exempt;
>    new_dir_cfg->is_httpbl_enabled          = 
>subdir->is_httpbl_enabled;
>    new_dir_cfg->something                  =
>(subdir->something)?apr_pstrdup(p, subdir->something):NULL;
>    new_dir_cfg->the_rbl_handlers           = (rbl_handler 
>**)apr_pcalloc(
>p, (MAX_RBL_DIRECTIVES)*sizeof(rbl_handler*) );
>    new_dir_cfg->num_of_rbl_handlers        = 0;
>
>    rbl_handler*    from_rbl_handler;
>    rbl_handler*    to_rbl_handler;
>    // fill in rbl directives starting with the parent, then the 
>child
>(returning an error string if more than MAX_RBL_DIRECTIVES 
>rbl_handlers are
>created/attempted
>    for (i = 0; i < parent_dir->num_of_rbl_handlers &&
>new_dir_cfg->num_of_rbl_handlers <= MAX_RBL_DIRECTIVES; i++)
>    {
>        from_rbl_handler    = parent_dir->the_rbl_handlers[i];
>        to_rbl_handler      = new_dir_cfg->the_rbl_handlers[i];
>
>        if (from_rbl_handler)
>        {
>            apr_copy_rbhlcpy(p, from_rbl_handler, to_rbl_handler);
>//            memcpy(to_rbl_handler, from_rbl_handler, 
>sizeof(rbl_handler));
>// try a direct memory copy
>            (new_dir_cfg->num_of_rbl_handlers)++;
>        }
>    }
>    for (j = 0; j < subdir->num_of_rbl_handlers &&
>new_dir_cfg->num_of_rbl_handlers < MAX_RBL_DIRECTIVES; j++)
>    {
>        from_rbl_handler    = subdir->the_rbl_handlers[j];
>        to_rbl_handler      = new_dir_cfg->the_rbl_handlers[i];
>
>        if (from_rbl_handler)
>        {
>            apr_copy_rbhlcpy(p, from_rbl_handler, to_rbl_handler);
>//            memcpy(to_rbl_handler, from_rbl_handler, 
>sizeof(rbl_handler));
>// try a direct memory copy
>            (new_dir_cfg->num_of_rbl_handlers)++;
>            i++;
>        }
>    }
>
>    return new_dir_cfg;
>}
>
>
>/* end code snippet */
>
>Dave

_________________________________________________________________
与联机的朋友进行交流,请使用 Live Messenger; 
http://get.live.com/messenger/overview 


Mime
View raw message