@@ -231,9 +231,7 @@ static PyObject* PyCompat_Encode(enum asn_transfer_syntax ats,
231231
232232#define PY_IMPL_DEALLOC (name , type_DEF ) \
233233 static void PyAsn##name##__dealloc(PyAsn##name##Object* self) { \
234- ASN_DEBUG("Freeing " #name " at %p (parent: %p)", self->ob_value, \
235- self->ob_parent); \
236- if (self->ob_parent != NULL) { \
234+ if (self->ob_parent != NULL) { \
237235 if (Py_REFCNT(self->ob_parent) < 1) { \
238236 PyErr_SetString(PyExc_MemoryError, \
239237 "UAF: parent object already deleted!"); \
@@ -672,16 +670,21 @@ static PyObject* PyCompat_Encode(enum asn_transfer_syntax ats,
672670 Py_XDECREF(tmp); \
673671 return result;
674672
675- #define PY_IMPL_CHOICE_INIT_ATTR (typeName , attrName , srcObj , tmpValue ) \
676- PyCompat_GenericGetAttr((srcObj), attrName, (tmpValue)); \
677- if ((tmpValue)) { \
678- if (PyAsn##typeName##__##attrName##_FromPython((tmpValue), (dst)) < \
679- 0) { \
680- Py_DECREF((tmpValue)); \
681- return -1; \
682- } \
683- } else \
684- PyErr_Clear();
673+ #define PY_IMPL_CHOICE_INIT_ATTR (typeName , enumTypeName , attrName ) \
674+ if (result == 0) { \
675+ PyCompat_GenericGetAttr(pObj, attrName, tmp); \
676+ if (tmp != NULL) { \
677+ if (PyAsn##typeName##__##attrName##_FromPython(tmp, pDst) < 0) { \
678+ result = -1; \
679+ } else { \
680+ pDst->present = enumTypeName##_PR_##attrName; \
681+ Py_CLEAR(tmp); \
682+ return 0; \
683+ } \
684+ } else { \
685+ PyErr_Clear(); \
686+ } \
687+ }
685688
686689#define PY_IMPL_CHOICE_INIT (typeName ) \
687690 PY_IMPL_CHOICE_INIT_GENERIC(typeName, typeName)
@@ -1125,8 +1128,6 @@ static PyObject* PyCompat_Encode(enum asn_transfer_syntax ats,
11251128
11261129#define PY_IMPL_SEQ_OF_DEALLOC (typeName , EMPTY_FUNC ) \
11271130 static void PyAsn##typeName##__dealloc(PyAsn##typeName##Object* self) { \
1128- ASN_DEBUG("Freeing " #typeName " object (value=%p, parent=%p)", \
1129- self->ob_value, self->ob_parent); \
11301131 if (self->ob_parent) { \
11311132 if (Py_REFCNT(self->ob_parent) < 1) { \
11321133 PyErr_SetString(PyExc_MemoryError, \
@@ -1138,10 +1139,6 @@ static PyObject* PyCompat_Encode(enum asn_transfer_syntax ats,
11381139 } else { \
11391140 if (self->ob_value != NULL) { \
11401141 if (self->ob_value->list.count > 0) { \
1141- ASN_DEBUG("Freeing elements of " #typeName \
1142- " (count=%d, list=%p)", \
1143- self->ob_value->list.count, \
1144- self->ob_value->list.array); \
11451142 EMPTY_FUNC((void*)&self->ob_value->list); \
11461143 } \
11471144 PyMem_RawFree(self->ob_value); \
@@ -1171,6 +1168,7 @@ static PyObject* PyCompat_Encode(enum asn_transfer_syntax ats,
11711168 if (item_value == NULL) { \
11721169 goto end; \
11731170 } \
1171+ memset(item_value, 0, sizeof(memberTypeName)); \
11741172 if (PyAsn##typeName##__component_FromPython(item, item_value) < \
11751173 0) { \
11761174 goto end; \
0 commit comments