apr_bucket_destroy is defined in apr_buckets.h as follows... #define apr_bucket_destroy(e) do { \ e->type->destroy(e->data); \ free(e); \ } while(0)
The problem is the presence of free(e); specifically, freeing the bucket directly in this macro ties -all- buckets, even custom user buckets, to the same memory management scheme (CRT in this case). Folks that want to write custom buckets may not want to use APRs default bucket memory management. Saeid Sakhitab in the IBM AS/400 team pointed this out to me and has a couple of suggestions on how to fix this. Fix 1... Pass the entire bucket to the destroy function and let destroy free the bucket right before return. #define apr_bucket_destroy(e) do { \ e->type->destroy(e); \ /* e is freed in destroy() */ } while(0) One irritation with this method is that the destroy() function is called internal in many of the bucket functions (search for file_destroy() in apr_bucket_file to see what I mean). Fix 2 Define a new field in the generic bucket structure, a pointer to a function to free the bucket. For example: #define apr_bucket_destroy(e) do { \ e->type->destroy(e->data); \ e->type->free(e); \ } while(0) This requires each bucket implement a free() function. Any strong opinions on which way to go (or suggestions for an entirely different solution)? I'll implement whichever one the group decides on. Bill