Hi guys,

I'm writing an apache module in C using EAPI that
comes with mod_ssl.

My module caches info in the array of structs that
is allocated from shared memory resource pool like
so:

/* globals */
static array_header *cache;
static pool *sp; 

/* my struct */
typedef struct {
      ..
    char *info;
    char *timestamp;
     ..
} mystruct;

/* module_init function */
static void module_init(server_rec *s, pool *p)
{
    sp = ap_make_shared_sub_pool(p);
    cache = ap_make_array(sp, 0, sizeof(mystruct));
}      

In my request handler I add/read elements from 
my cache array. Now the problem is, I need to be able to 
delete from my cache array in shared memory "old" elements 
(eg. timestamp > N seconds) so that my cache doesnt become 
huge and eat-up all my RAM...

Since apache doesnt provide an easy way of popping out
elements from its arrays here is what I tried to do
to achieve that
 
1) create a temporary array TEMPO
   from r->pool and copy in there all the elements
   from cache array that I want to keep

2) call ap_clear_pool(sp) on my shared memory pool to 
   destroy  its content. 

3) Re-create an empty array  in shared memory again  
   cache = ap_make_array(sp, 0, sizeof(mystruct))
  
4) Push into my newly recreated array all elements from temporary
   array. 

Note: In my code I always remember to set and release lockes whenever I
read/write into my shared pool.

Now obviously if my program worked flawlessly I wouldn't we writing this 
email ;o)

After about thousand requests my apache children start seg-faulting
and I start getting this error "Ouch!  malloc failed in malloc_block()".

Im 100% sure the problem is caused by me tring to free up memory
in shared pool when I re-create my cache array in there, because
if I skip that part and only add elements into my cache my 
program works perfectly... of course my available shared memory is getting
smaller and smaller in that case.


 








______________________________________________________________________
Apache Interface to OpenSSL (mod_ssl)                   www.modssl.org
User Support Mailing List                      [EMAIL PROTECTED]
Automated List Manager                            [EMAIL PROTECTED]

Reply via email to