X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_resource_factory.c;h=0813755f06328e47a657f07dd711b8e4b10031ca;hp=3135e4786f2929359c3c81c6af3881ebaefd58ba;hb=517336efe27e1f8e58e36352478a6d9ffdcdf378;hpb=29a54250b58e444974ae19840194e214cab80bd5 diff --git a/php_http_resource_factory.c b/php_http_resource_factory.c index 3135e47..0813755 100644 --- a/php_http_resource_factory.c +++ b/php_http_resource_factory.c @@ -24,21 +24,35 @@ PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_htt f->data = data; f->dtor = dtor; + f->refcount = 1; + return f; } +PHP_HTTP_API unsigned php_http_resource_factory_addref(php_http_resource_factory_t *rf) +{ + return ++rf->refcount; +} + PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f) { - if (f->dtor) { - f->dtor(f->data); + --f->refcount; + + if (!f->refcount) { + if (f->dtor) { + f->dtor(f->data); + } } } + PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f) { if (*f) { php_http_resource_factory_dtor(*f); - efree(*f); - *f = NULL; + if (!(*f)->refcount) { + efree(*f); + *f = NULL; + } } }