Fri, 10 Mar 2023 23:00:02 +0100
resourcepool_free should remove the resource from the request resource cache
--- a/src/server/daemon/httprequest.c Fri Mar 10 22:45:58 2023 +0100 +++ b/src/server/daemon/httprequest.c Fri Mar 10 23:00:02 2023 +0100 @@ -601,6 +601,7 @@ } int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) { + rq->finished = TRUE; request_free_resources(sn, rq); WSBool read_stream_eof = httpstream_eof(sn->sn.csd);
--- a/src/server/daemon/request.h Fri Mar 10 22:45:58 2023 +0100 +++ b/src/server/daemon/request.h Fri Mar 10 23:00:02 2023 +0100 @@ -49,6 +49,7 @@ NSAPIContext context; void *jvm_context; CxMap *resources; + WSBool finished; }; /* macros for context access */
--- a/src/server/daemon/resourcepool.c Fri Mar 10 22:45:58 2023 +0100 +++ b/src/server/daemon/resourcepool.c Fri Mar 10 23:00:02 2023 +0100 @@ -60,6 +60,12 @@ return 1; } + char *respool_name = cx_strdup_a(cfg->a, name).ptr; + if(!respool_name) { + log_ereport(LOG_FAILURE, "resourcepool_new: OOM"); + return 1; + } + // convert ConfigNode to pblock // no sub-objects allowed for this specific ConfigNode, therefore // it can be represented as key-value-pairs @@ -82,6 +88,7 @@ return 1; } + respool->name = respool_name; respool->type = restype; respool->data = respool_data; respool->min = 4; // TODO: get from node @@ -211,9 +218,18 @@ } void resourcepool_free(Session *sn, Request *rq, ResourceData *resource) { + NSAPIRequest *nsapi_rq = (NSAPIRequest *)rq; ResourceDataPrivate *res = (ResourceDataPrivate*)resource; ResourcePool *respool = resource->resourcepool; + if(nsapi_rq && !nsapi_rq->finished) { + // request processing still ongoing and SAFs will be executed + if(!cxMapRemove(nsapi_rq->resources, cx_hash_key_str(respool->name))) { + log_ereport(LOG_FAILURE, "resourcepool_free: cannot remove resource from request: potential double free"); + } + } + // else: safe to ignore nsapi_rq->resources + if(respool->type->finish(respool->data, res->resdata)) { log_ereport(LOG_FAILURE, "resourcepool_free: finish failed"); }
--- a/src/server/daemon/resourcepool.h Fri Mar 10 22:45:58 2023 +0100 +++ b/src/server/daemon/resourcepool.h Fri Mar 10 23:00:02 2023 +0100 @@ -67,6 +67,11 @@ ResourceType *type; /* + * The name of the resource pool + */ + char *name; + + /* * Data returned by the ResourceType init function * When the pool is destroyed, the data should be passed to * ResourceType.destroy