aaron 2003/10/06 13:31:59
Modified: misc apr_reslist.c
Log:
Return errors from constructors all the way back through to the consumer.
Also make sure to free up resources that were created for a call to
a constructor if that constructor fails. (Fixes a minor memory leak.)
Also clean up some of the return statements to make them more readable.
Submitted by: Snke Tesch <[EMAIL PROTECTED]>
Reviewed by: Aaron Bannert
PR: 23492
Revision Changes Path
1.5 +6 -20 apr-util/misc/apr_reslist.c
Index: apr_reslist.c
===================================================================
RCS file: /home/cvs/apr-util/misc/apr_reslist.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- apr_reslist.c 18 Sep 2003 06:21:11 -0000 1.4
+++ apr_reslist.c 6 Oct 2003 20:31:59 -0000 1.5
@@ -157,12 +157,9 @@
res = apr_pcalloc(reslist->pool, sizeof(*res));
rv = reslist->constructor(&res->opaque, reslist->params, reslist->pool);
- if (rv != APR_SUCCESS) {
- return rv;
- }
*ret_res = res;
- return APR_SUCCESS;
+ return rv;
}
/**
@@ -171,14 +168,7 @@
*/
static apr_status_t destroy_resource(apr_reslist_t *reslist, apr_res_t *res)
{
- apr_status_t rv;
-
- rv = reslist->destructor(res->opaque, reslist->params, reslist->pool);
- if (rv != APR_SUCCESS) {
- return rv;
- }
-
- return APR_SUCCESS;
+ return reslist->destructor(res->opaque, reslist->params, reslist->pool);
}
static apr_status_t reslist_cleanup(void *data_)
@@ -368,17 +358,13 @@
* a resource to fill the slot and use it. */
else {
rv = create_resource(reslist, &res);
-
- if (rv != APR_SUCCESS) {
- apr_thread_mutex_unlock(reslist->listlock);
- return rv;
+ if (rv == APR_SUCCESS) {
+ reslist->ntotal++;
+ *resource = res->opaque;
}
-
- reslist->ntotal++;
- *resource = res->opaque;
free_container(reslist, res);
apr_thread_mutex_unlock(reslist->listlock);
- return APR_SUCCESS;
+ return rv;
}
}