Fix T46848: OpenNL crash on Windows due to uninintialized variables.
authorBrecht Van Lommel <brecht@solidangle.com>
Mon, 23 Nov 2015 17:20:32 +0000 (18:20 +0100)
committerBrecht Van Lommel <brecht@solidangle.com>
Mon, 23 Nov 2015 17:20:32 +0000 (18:20 +0100)
intern/opennl/intern/opennl.cpp

index 076dce3b8077f6d4294847f522e749fd8e3373f4..446a1a38f0d372b2752c614b3f8be6db970c86bb 100644 (file)
@@ -77,6 +77,24 @@ typedef struct {
 #define NL_STATE_SYSTEM_SOLVED      5
 
 struct NLContext {
+   NLContext()
+   {
+      state = NL_STATE_INITIAL;
+      n = 0;
+      m = 0;
+      sparse_solver = NULL;
+      nb_variables = 0;
+      nb_rhs = 1;
+      nb_rows = 0;
+      least_squares = false;
+      solve_again = false;
+   }
+
+   ~NLContext()
+   {
+      delete sparse_solver;
+   }
+
        NLenum state;
 
        NLuint n;
@@ -103,24 +121,11 @@ struct NLContext {
 
 NLContext *nlNewContext(void)
 {
-       NLContext* result = new NLContext();
-       result->state = NL_STATE_INITIAL;
-       result->nb_rhs = 1;
-       return result;
+       return new NLContext();
 }
 
 void nlDeleteContext(NLContext *context)
 {
-       context->M.resize(0, 0);
-       context->MtM.resize(0, 0);
-       context->b.clear();
-       context->Mtb.clear();
-       context->x.clear();
-       context->variable.clear();
-
-       delete context->sparse_solver;
-       context->sparse_solver = NULL;
-
        delete context;
 }