Index: ../trunk-jpl/src/c/cores/controlm1qn3_core.cpp
===================================================================
--- ../trunk-jpl/src/c/cores/controlm1qn3_core.cpp	(revision 18890)
+++ ../trunk-jpl/src/c/cores/controlm1qn3_core.cpp	(revision 18891)
@@ -10,7 +10,7 @@
 #include "../modules/modules.h"
 #include "../solutionsequences/solutionsequences.h"
 
-#if defined (_HAVE_M1QN3_)
+#if defined (_HAVE_M1QN3_) & !defined(_HAVE_ADOLC_)
 /*m1qn3 prototypes*/
 extern "C" void *ctonbe_; // DIS mode : Conversion
 extern "C" void *ctcabe_; // DIS mode : Conversion
Index: ../trunk-jpl/src/c/cores/controlad_core.cpp
===================================================================
--- ../trunk-jpl/src/c/cores/controlad_core.cpp	(revision 18890)
+++ ../trunk-jpl/src/c/cores/controlad_core.cpp	(revision 18891)
@@ -157,13 +157,16 @@
 	char* lockfilename=NULL;
 	IssmPDouble* G2=NULL;
 	bool onsid=true;
-
-	/*Recover Femmodel*/
+	IssmDouble  *XL = NULL;
+	IssmDouble  *XU = NULL;
 	int         solution_type;
-	FemModel   *femmodel  = (FemModel*)dzs;
+	FemModel   *femmodel  =  NULL;
 	FemModel   *femmodelad  = NULL;
 	IssmDouble    pfd;
 	int            i;
+	
+	/*Recover Femmodel*/
+	femmodel  = (FemModel*)dzs;
 
 	/*Recover number of cost functions responses*/
 	int num_responses,num_controls,numberofvertices;
@@ -174,8 +177,6 @@
 	numberofvertices=femmodel->vertices->NumberOfVertices();
 
 	/*Constrain input vector*/
-	IssmDouble  *XL = NULL;
-	IssmDouble  *XU = NULL;
 	GetVectorFromControlInputsx(&XL,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"lowerbound",onsid);
 	GetVectorFromControlInputsx(&XU,femmodel->elements,femmodel->nodes,femmodel->vertices,femmodel->loads,femmodel->materials,femmodel->parameters,"upperbound",onsid);
 	for(int i=0;i<numberofvertices;i++){
@@ -216,8 +217,12 @@
 	ad_core(femmodel); 
 
 	if(IssmComm::GetRank()==0){
+		IssmPDouble* G_temp=NULL;
 		GenericExternalResult<IssmPDouble*>* gradient=(GenericExternalResult<IssmPDouble*>*)femmodel->results->FindResult(AutodiffJacobianEnum); _assert_(gradient);
-		G2=gradient->GetValues();
+		G_temp=gradient->GetValues();
+		/*copy onto G2, to avoid a leak: */
+		G2=xNew<IssmPDouble>(*n); 
+		xMemCpy<IssmPDouble>(G2,G_temp,*n);
 	}
 	else G2=xNew<IssmPDouble>(*n);
 
@@ -251,7 +256,14 @@
 	xDelete<IssmDouble>(XU);
 	xDelete<IssmDouble>(XL);
 	xDelete<IssmPDouble>(G2);
-	//if(femmodelad)delete femmodelad;
+	
+	xDelete<char>(rootpath);
+	xDelete<char>(inputfilename
+	xDelete<char>(outputfilename);
+	xDelete<char>(toolkitsfilename);
+	xDelete<char>(lockfilename);
+	if(femmodelad)delete femmodelad;
+
 } /*}}}*/
 #else
 void controlad_core(FemModel* femmodel){ /*{{{*/
