Index: /issm/trunk-jpl/src/c/modules/AllocateSystemMatricesx/AllocateSystemMatricesx.cpp
===================================================================
--- /issm/trunk-jpl/src/c/modules/AllocateSystemMatricesx/AllocateSystemMatricesx.cpp	(revision 16437)
+++ /issm/trunk-jpl/src/c/modules/AllocateSystemMatricesx/AllocateSystemMatricesx.cpp	(revision 16438)
@@ -24,4 +24,5 @@
 
 	bool oldalloc=false;
+	char* toolkittype=NULL;
 
 	/*retrieve parameters: */
@@ -36,4 +37,9 @@
 
 	numberofdofspernode=femmodel->nodes->MaxNumDofs(configuration_type,GsetEnum);
+
+	/*if our matrices are coming from issm, we don't do dynamic allocation like Petsc 
+	 * does, and this routine is essentially useless. Force oldalloc in this case: */
+	toolkittype=ToolkitOptions::GetToolkitType();
+	if(strcmp(toolkittype,"issm")==0)oldalloc=true;
 
 	if(oldalloc){
@@ -63,4 +69,7 @@
 		if(ppf) pf =new Vector<IssmDouble>(flocalsize,fsize);
 	}
+	
+	/*Free ressources: */
+	xDelete<char>(toolkittype);
 
 	/*Allocate output pointers*/
Index: /issm/trunk-jpl/src/c/toolkits/issm/SparseRow.h
===================================================================
--- /issm/trunk-jpl/src/c/toolkits/issm/SparseRow.h	(revision 16437)
+++ /issm/trunk-jpl/src/c/toolkits/issm/SparseRow.h	(revision 16438)
@@ -13,4 +13,7 @@
 class SparseRow{
 
+	private:
+		int*        buffer; //used during SetValues
+
 	public:
 
@@ -19,5 +22,5 @@
 		int*        indices;
 		doubletype* values;
-
+		
 		/*SparseRow constructors, destructors*/
 		SparseRow(){ /*{{{*/
@@ -26,4 +29,5 @@
 			 indices=NULL;
 			 values=NULL;
+			 buffer=NULL;
 		} /*}}}*/
 		SparseRow(int in_M){/*{{{*/
@@ -33,4 +37,6 @@
 			indices=NULL;
 			values=NULL;
+
+			buffer=xNewZeroInit<int>(M);
 		} /*}}}*/
 		~SparseRow(){/*{{{*/
@@ -39,4 +45,5 @@
 				xDelete<doubletype>(values);
 			}
+			if(buffer)xDelete<int>(buffer);
 		} /*}}}*/
 
@@ -53,5 +60,4 @@
 			int count;
 			int i,j;
-			int* buffer=NULL;
 
 			if(!M)_error_("unknow dimension for this sparse row!");
@@ -67,6 +73,9 @@
 
 			/*Figure out number of non-zero values ncols: */
-			buffer=xNewZeroInit<int>(M);
+			for(i=0;i<numvalues;i++)buffer[i]=0;
+			
+			ncols=0;
 			for(i=0;i<numvalues;i++){
+				if(!buffer[cols[i]])ncols++;
 				if(mods[i]==ADD_VAL){
 					if(buffer[cols[i]]!=2)buffer[cols[i]]=1;
@@ -74,8 +83,4 @@
 				else buffer[cols[i]]=2;
 			}
-			ncols=0;
-			for(i=0;i<M;i++)if(buffer[i]!=0)ncols++;
-			_assert_(ncols);
-
 
 			/*Allocate:*/
@@ -109,8 +114,4 @@
 			}
 			if(count!=ncols)_error_("counter problem during set values operations");
-
-			/*Free ressources: */
-			xDelete<int>(buffer);
-
 		} /*}}}*/
 		doubletype Norm(NormMode mode){ /*{{{*/
