From 70c386cddf47c5dc9491c15d04dea97c2e8e51f4 Mon Sep 17 00:00:00 2001
From: Stephen Swaney <sswaney@centurytel.net>
Date: Wed, 1 Dec 2004 23:09:59 +0000
Subject: [PATCH] bugfix: #1930 Mathutils.Euler constructor fails to initialize
 class variables

Euler object was holding pointer to bad memory.
Euler now owns internal array memory and frees it in destructor.
---
 source/blender/python/api2_2x/euler.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/source/blender/python/api2_2x/euler.c b/source/blender/python/api2_2x/euler.c
index d55b5814270..6b72460ccd4 100644
--- a/source/blender/python/api2_2x/euler.c
+++ b/source/blender/python/api2_2x/euler.c
@@ -150,6 +150,9 @@ PyObject *Euler_Zero( EulerObject * self )
 
 static void Euler_dealloc( EulerObject * self )
 {
+	/* since we own this memory... */
+	PyMem_Free( self->eul );
+
 	PyObject_DEL( self );
 }
 
@@ -330,13 +333,25 @@ PyObject *newEulerObject( float *eul )
 
 	self = PyObject_NEW( EulerObject, &euler_Type );
 
+	/* 
+	   we own the self->eul memory and will free it later.
+	   if we received an input arg, copy to our internal array
+	*/
+
+	self->eul = PyMem_Malloc( 3 * sizeof( float ) );
+	if( ! self->eul )
+		return EXPP_ReturnPyObjError( PyExc_MemoryError,
+					      "newEulerObject:PyMem_Malloc failed" );
+	
 	if( !eul ) {
-		self->eul = PyMem_Malloc( 3 * sizeof( float ) );
 		for( x = 0; x < 3; x++ ) {
 			self->eul[x] = 0.0f;
 		}
-	} else
-		self->eul = eul;
+	} else{
+		for( x = 0; x < 3; x++){
+			self->eul[x] = eul[x];
+		}
+	}
 
 	return ( PyObject * ) self;
 }
-- 
GitLab