static apr_status_t clean_resp()

in src/outgoing_request.c [34:92]


static apr_status_t clean_resp(void *data)
{
    serf_request_t *request = data;
    apr_pool_t *respool = request->respool;

    /* Note that this function must handle rehooking several
       variables to a different request!

       See serf_connection__request_requeue() */

    request->respool = NULL;

    /* The request's RESPOOL is being cleared.  */
    if (respool && request->writing >= SERF_WRITING_STARTED
                && request->writing < SERF_WRITING_FINISHED) {

        /* HOUSTON, WE HAVE A PROBLEM.

           We created buckets inside the pool that is now cleaned and
           stored them in an aggregate that still lives on.

           This happens when the application decides that it doesn't
           need the connection any more and clears the pool of the
           connection, of which the request pool is a subpool.

           Let's ask the connection to take care of things */
        serf__connection_pre_cleanup(request->conn);
    }

#ifdef SERF_DEBUG_BUCKET_USE
    if (respool && request->allocator) {
        serf_debug__closed_conn(request->allocator);
    }
#endif

    /* If the response has allocated some buckets, then destroy them (since
       the bucket may hold resources other than memory in RESPOOL). Also
       make sure to set their fields to NULL so connection closure does
       not attempt to free them again.  */
    if (request->resp_bkt) {
        serf_bucket_destroy(request->resp_bkt);
        request->resp_bkt = NULL;
    }
    if (request->req_bkt) {
        if (request->writing == SERF_WRITING_NONE)
            serf_bucket_destroy(request->req_bkt);
        request->req_bkt = NULL;
    }

#ifdef SERF_DEBUG_BUCKET_USE
    if (respool && request->allocator) {
        serf_debug__bucket_alloc_check(request->allocator);
    }
#endif

    request->allocator = NULL;

    return APR_SUCCESS;
}