summaryrefslogtreecommitdiff
path: root/source3/python/py_tdbpack.c
diff options
context:
space:
mode:
authorMartin Pool <mbp@samba.org>2002-12-12 05:24:55 +0000
committerMartin Pool <mbp@samba.org>2002-12-12 05:24:55 +0000
commitaabcd65020396105c683ede6fd9b5bb01891b098 (patch)
treebdeb77436b156abab0a51e4bbb962d7150936647 /source3/python/py_tdbpack.c
parent022a8537811115b20e21c3e7551d465fe606cb44 (diff)
downloadsamba-aabcd65020396105c683ede6fd9b5bb01891b098.tar.gz
samba-aabcd65020396105c683ede6fd9b5bb01891b098.tar.bz2
samba-aabcd65020396105c683ede6fd9b5bb01891b098.zip
CR1333: Fix memory leak when unpacking some structures.
* (pytdbunpack_item): PyList_Append creates an additional reference to the appended object. Therefore, release the initial reference after it's added to the list. (This used to be commit 1e63dc101a5085a46b9632ba657e5d5cd7505751)
Diffstat (limited to 'source3/python/py_tdbpack.c')
-rw-r--r--source3/python/py_tdbpack.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c
index 28cd529245..6181a4918e 100644
--- a/source3/python/py_tdbpack.c
+++ b/source3/python/py_tdbpack.c
@@ -656,21 +656,21 @@ pytdbunpack_buffer(char **pbuf, int *plen, PyObject *val_list)
Returns a reference to None, or NULL for failure.
*/
static PyObject *pytdbunpack_item(char ch,
- char **pbuf,
- int *plen,
- PyObject *val_list)
+ char **pbuf,
+ int *plen,
+ PyObject *val_list)
{
- PyObject *result;
+ PyObject *unpacked;
if (ch == 'w') { /* 16-bit int */
- result = pytdbunpack_int16(pbuf, plen);
+ unpacked = pytdbunpack_int16(pbuf, plen);
}
else if (ch == 'd' || ch == 'p') { /* 32-bit int */
/* pointers can just come through as integers */
- result = pytdbunpack_uint32(pbuf, plen);
+ unpacked = pytdbunpack_uint32(pbuf, plen);
}
else if (ch == 'f' || ch == 'P') { /* nul-term string */
- result = pytdbunpack_string(pbuf, plen, pytdb_unix_encoding);
+ unpacked = pytdbunpack_string(pbuf, plen, pytdb_unix_encoding);
}
else if (ch == 'B') { /* length, buffer */
return pytdbunpack_buffer(pbuf, plen, val_list);
@@ -684,10 +684,15 @@ static PyObject *pytdbunpack_item(char ch,
}
/* otherwise OK */
- if (!result)
- return NULL;
- if (PyList_Append(val_list, result) == -1)
+ if (!unpacked)
return NULL;
+
+ if (PyList_Append(val_list, unpacked) == -1)
+ val_list = NULL;
+
+ /* PyList_Append takes a new reference to the inserted object.
+ Therefore, we no longer need the original reference. */
+ Py_DECREF(unpacked);
return val_list;
}