Rev 1874: Avoid leaking memory when aborting inside of init function. in file:///data/jelmer/bzr-svn/trunk/
Jelmer Vernooij
jelmer at samba.org
Tue Sep 9 01:32:09 BST 2008
At file:///data/jelmer/bzr-svn/trunk/
------------------------------------------------------------
revno: 1874
revision-id: jelmer at samba.org-20080909003205-hf9uz43x52kl3nw8
parent: jelmer at samba.org-20080908225453-6shaspzohbdj8kx3
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Tue 2008-09-09 02:32:05 +0200
message:
Avoid leaking memory when aborting inside of init function.
modified:
client.c client.pyx-20080313235339-wbyjbw2namuiql8f-1
ra.c ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
repos.c repos.pyx-20080314114432-g2b5lqe776tkbl4k-1
util.c util.c-20080531154025-s8ef6ej9tytsnkkw-1
=== modified file 'client.c'
--- a/client.c 2008-08-31 13:44:01 +0000
+++ b/client.c 2008-09-09 00:32:05 +0000
@@ -93,7 +93,7 @@
copyfrom = Py_BuildValue("(si)", commit_item->copyfrom_url,
commit_item->copyfrom_rev);
if (copyfrom == NULL) {
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
} else {
@@ -106,7 +106,7 @@
copyfrom,
commit_item->state_flags);
if (item == NULL) {
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
@@ -182,13 +182,12 @@
ret->pool = Pool(NULL);
if (ret->pool == NULL) {
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
if (!check_error(svn_client_create_context(&ret->client, ret->pool))) {
- apr_pool_destroy(ret->pool);
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
@@ -208,7 +207,8 @@
Py_XDECREF((PyObject *)client->client->log_msg_baton2);
Py_XDECREF(client->py_auth);
Py_XDECREF(client->py_config);
- apr_pool_destroy(client->pool);
+ if (client->pool != NULL)
+ apr_pool_destroy(client->pool);
PyObject_Del(self);
}
@@ -614,7 +614,9 @@
static void config_dealloc(PyObject *obj)
{
- apr_pool_destroy(((ConfigObject *)obj)->pool);
+ apr_pool_t *pool = ((ConfigObject *)obj)->pool;
+ if (pool != NULL)
+ apr_pool_destroy(pool);
PyObject_Del(obj);
}
=== modified file 'ra.c'
--- a/ra.c 2008-09-08 22:54:53 +0000
+++ b/ra.c 2008-09-09 00:32:05 +0000
@@ -725,6 +725,19 @@
if (ret == NULL)
return NULL;
+ ret->root = NULL;
+ ret->pool = Pool(NULL);
+ if (ret->pool == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+
+ ret->url = svn_path_canonicalize(url, ret->pool);
+ if (ret->url == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+
if ((PyObject *)auth == Py_None) {
auth_baton = NULL;
ret->auth = NULL;
@@ -735,22 +748,8 @@
auth_baton = ret->auth->auth_baton;
}
- ret->root = NULL;
- ret->pool = Pool(NULL);
- if (ret->pool == NULL) {
- PyObject_Del(ret);
- return NULL;
- }
-
- ret->url = svn_path_canonicalize(url, ret->pool);
- if (ret->url == NULL) {
- apr_pool_destroy(ret->pool);
- PyObject_Del(ret->pool);
- return NULL;
- }
if (!check_error(svn_ra_create_callbacks(&callbacks2, ret->pool))) {
- apr_pool_destroy(ret->pool);
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
@@ -767,8 +766,7 @@
#endif
config_hash = config_hash_from_object(config, ret->pool);
if (config_hash == NULL) {
- apr_pool_destroy(ret->pool);
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
Py_BEGIN_ALLOW_THREADS
@@ -776,8 +774,7 @@
callbacks2, ret, config_hash, ret->pool);
Py_END_ALLOW_THREADS
if (!check_error(err)) {
- apr_pool_destroy(ret->pool);
- PyObject_Del(ret);
+ Py_DECREF(ret);
return NULL;
}
ret->busy = false;
@@ -2056,12 +2053,15 @@
if (!PyList_Check(providers)) {
PyErr_SetString(PyExc_TypeError, "Auth providers should be list");
+ Py_DECREF(ret);
return NULL;
}
ret->pool = Pool(NULL);
- if (ret->pool == NULL)
+ if (ret->pool == NULL) {
+ Py_DECREF(ret);
return NULL;
+ }
ret->providers = providers;
Py_INCREF(providers);
@@ -2069,6 +2069,7 @@
c_providers = apr_array_make(ret->pool, PyList_Size(providers), sizeof(svn_auth_provider_object_t *));
if (c_providers == NULL) {
PyErr_NoMemory();
+ Py_DECREF(ret);
return NULL;
}
for (i = 0; i < PyList_Size(providers); i++) {
@@ -2280,7 +2281,7 @@
{
AuthObject *auth = (AuthObject *)self;
apr_pool_destroy(auth->pool);
- Py_DECREF(auth->providers);
+ Py_XDECREF(auth->providers);
}
PyTypeObject Auth_Type = {
=== modified file 'repos.c'
--- a/repos.c 2008-08-31 13:44:01 +0000
+++ b/repos.c 2008-09-09 00:32:05 +0000
@@ -74,12 +74,14 @@
RepositoryObject *repos = (RepositoryObject *)self;
apr_pool_destroy(repos->pool);
+ PyObject_Del(repos);
}
static PyObject *repos_init(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
char *path;
char *kwnames[] = { "path", NULL };
+ svn_error_t *err;
RepositoryObject *ret;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwnames, &path))
@@ -93,13 +95,12 @@
if (ret->pool == NULL)
return NULL;
Py_BEGIN_ALLOW_THREADS
- if (!check_error(svn_repos_open(&ret->repos, path, ret->pool))) {
- apr_pool_destroy(ret->pool);
- PyEval_RestoreThread(_save);
- PyObject_Del(ret);
- return NULL;
- }
+ err = svn_repos_open(&ret->repos, path, ret->pool);
Py_END_ALLOW_THREADS
+ if (!check_error(err)) {
+ Py_DECREF(ret);
+ return NULL;
+ }
return (PyObject *)ret;
}
=== modified file 'util.c'
--- a/util.c 2008-08-30 03:08:49 +0000
+++ b/util.c 2008-09-09 00:32:05 +0000
@@ -407,6 +407,7 @@
PyObject *key, *value;
apr_hash_t *config_hash;
PyObject *dict;
+
if (config == Py_None) {
RUN_SVN_WITH_POOL(pool,
svn_config_get_config(&config_hash, NULL, pool));
More information about the bazaar-commits
mailing list