Sun, 08 May 2022 12:07:58 +0200
fix resource pool memory management
src/server/daemon/resourcepool.c | file | annotate | diff | comparison | revisions | |
src/server/plugins/postgresql/resource.c | file | annotate | diff | comparison | revisions |
--- a/src/server/daemon/resourcepool.c Sun May 08 11:52:52 2022 +0200 +++ b/src/server/daemon/resourcepool.c Sun May 08 12:07:58 2022 +0200 @@ -87,6 +87,10 @@ respool->min = 4; // TODO: get from node respool->max = RESOURCE_POOL_MAX_DEFAULT; // TODO: get from node + respool->numcreated = 0; + respool->numresources = 0; + + // don't allow too large resource pools // this prevents the need to check malloc integer overflows if(respool->max > RESOURCE_POOL_MAX_ALLOC) { @@ -141,7 +145,7 @@ if(resourceData) { respool->numcreated++; - resource = pool_malloc(sn->pool, sizeof(ResourceDataPrivate)); + resource = pool_malloc(respool->pool, sizeof(ResourceDataPrivate)); if(resource) { resource->data.data = respool->type->getresourcedata(resourceData); resource->data.resourcepool = respool;
--- a/src/server/plugins/postgresql/resource.c Sun May 08 11:52:52 2022 +0200 +++ b/src/server/plugins/postgresql/resource.c Sun May 08 12:07:58 2022 +0200 @@ -115,6 +115,7 @@ if(res->connection) { PQfinish(res->connection); } + pool_free(pg->pool, res); } int pg_resourcepool_prepare(PgResourcePool *pg, PgResource *res) {