Bojan Smojver
Fri, 18 Jul 2008 23:16:39 -0700
On Sat, 2008-07-19 at 06:12 +0200, Mladen Turk wrote: > But not with pre_cleanup. Could you try running this? I get an infinite loop (CPU pegged at 100%) even with pre_cleanup. If I change the code to this: apr_reslist_create(&list,0,10,10,0,con,de,NULL,pool); I get double free. Either that pre_cleanup thing doesn't work as expected, or I'm going nuts. I tried to simplify the example to avoid bugs, but maybe I've been looking at it for too long... -- Bojan
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <apr.h>
#include <apr_pools.h>
#include <apr_strings.h>
#include <apr_reslist.h>
struct res{
apr_pool_t *p;
char *r;
};
static apr_status_t con(void **res,void *parm,apr_pool_t *pool){
apr_pool_t *rpool;
struct res **r=(struct res **)res;
apr_pool_create(&rpool,pool);
*r=apr_palloc(rpool,sizeof(**r));
(*r)->p=rpool;
return APR_SUCCESS;
}
static apr_status_t de(void *res,void *parm,apr_pool_t *pool){
struct res *r=res;
apr_pool_destroy(r->p);
return APR_SUCCESS;
}
int main(int argc,char **argv){
int i,j,k;
struct res *r[10];
apr_pool_t *pool;
apr_reslist_t *list;
apr_initialize();
for(k=0;k<10;k++){
apr_pool_create(&pool,NULL);
apr_reslist_create(&list,0,k%11,10,0,con,de,NULL,pool);
for(j=1;j<=10;j++){
for(i=0;i<j;i++)
apr_reslist_acquire(list,(void **)&r[i]);
for(i=0;i<j;i++)
apr_reslist_release(list,r[i]);
}
apr_pool_destroy(pool);
}
apr_terminate();
return 0;
}