pytalloc: ensure talloc_ctx is directly after PyObject_HEAD
authorAndrew Tridgell <tridge@samba.org>
Tue, 20 Apr 2010 05:33:00 +0000 (15:33 +1000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 20 Apr 2010 05:50:27 +0000 (15:50 +1000)
commitf1c523939b88aee0b1ce7375d68b06a0b8cf5d28
treeaae27335d6a01e6ffaaf2a7901ef6b1aa14eae3d
parent45be1c7ba4382d85c742a241687bbc6d5a2ebd8c
pytalloc: ensure talloc_ctx is directly after PyObject_HEAD

the talloc python interface for tp_alloc and tp_dealloc relies on a
cast to a py_talloc_Object to find the talloc_ctx (see
py_talloc_dealloc). This means we rely on the talloc_ctx for the
object being directly after the PyObject_HEAD

This fixes the talloc free with references bug in samba_dnsupdate

The actual problem was the tp_alloc() call in
PyCredentialCacheContainer_from_ccache_container() which used a cast
from a py_talloc_Object to a PyCredentialCacheContainerObject. That
case effectively changed the parent/child relationship between the
talloc_ctx and the ccc ptr.

This patch changes all the structures that follow this pattern to put
the TALLOC_CTX directly after the PyObject_HEAD, to ensure that if
anyone else decides to do a dangerous cast like this that it won't
cause the same sort of subtle breakage.

Pair-Programmed-With: Rusty Russell <rusty@samba.org>
source4/auth/credentials/pycredentials.h
source4/lib/ldb/pyldb.h
source4/lib/messaging/pymessaging.c
source4/libnet/py_net.c