Skip to content

Commit 3ac0b2a

Browse files
cipherboyDirectXMan12
authored andcommitted
OIDs: Copy constructor take ownership
When constructing via a the cpy parameter, cpy would maintain ownership; if cpy._free_on_dealloc was set to true, the new object could have memory freed while still maintaining a reference to it. This fixes the issue by having the new object take ownership. To perform a memory copy, use the elements argument to the constructor. Signed-off-by: Alexander Scheel <[email protected]>
1 parent 5f213d8 commit 3ac0b2a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

gssapi/raw/oids.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,20 @@ cdef class OID:
3232
# cdef bint _free_on_dealloc = NULL
3333

3434
def __cinit__(OID self, OID cpy=None, elements=None):
35+
"""
36+
Note: cpy is named such for historical reasons. To perform a deep
37+
copy, specify the elements parameter; this will copy the value of the
38+
OID. To perform a shallow copy and take ownership of an existing OID,
39+
use the cpy (default) argument.
40+
"""
3541
if cpy is not None and elements is not None:
3642
raise TypeError("Cannot instantiate a OID from both a copy and "
3743
" a new set of elements")
3844
if cpy is not None:
3945
self.raw_oid = cpy.raw_oid
46+
# take ownership of this OID (for dynamic cases)
47+
self._free_on_dealloc = cpy._free_on_dealloc
48+
cpy._free_on_dealloc = False
4049

4150
if elements is None:
4251
self._free_on_dealloc = False

0 commit comments

Comments
 (0)