Index: /issm/trunk-jpl/test/NightlyRun/runme.m
===================================================================
--- /issm/trunk-jpl/test/NightlyRun/runme.m	(revision 15718)
+++ /issm/trunk-jpl/test/NightlyRun/runme.m	(revision 15719)
@@ -21,6 +21,7 @@
 %                      'gia'   : validation of gia tests
 %                      ...
-%      'procedure'     'check' : run the test (default)
-%                      'update': update the archive
+%      'procedure'     'check' :   run the test (default)
+%                      'update':   update the archive
+%                      'valgrind': check for memory leaks (default value of md.debug.valgrind needs to be changed manually)
 %
 %   Usage:
@@ -56,5 +57,5 @@
 %GET procedure {{{
 procedure=getfieldvalue(options,'procedure','check');
-if ~ismember(procedure,{'check','update'})
+if ~ismember(procedure,{'check','update','valgrind'})
 	disp('runme warning: procedure not supported, defaulting to test ''check''')
 	procedure='check';
@@ -148,4 +149,32 @@
 			disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
 
+		%CHECK for memory leaks?
+		elseif strcmpi(procedure,'valgrind'),
+			fields = fieldnames(md.results);
+			for i=1:numel(fields)
+				if ~isfield(md.results.(fields{i}),'errlog'),
+					disp(['Skipping ' fields{i}]);
+					continue;
+				else
+					disp(['Extracting results of ' fields{i}]);
+				end
+				errlog = cellstr(md.results.(fields{i}).errlog);
+				lines  = strfind(errlog,'definitely lost:');
+				lines  = find(~cellfun(@isempty,lines));
+				total  = 0;
+				for j=1:numel(lines)
+					Line    = errlog(lines(j));
+					Numbers = sscanf(Line{1},'==%i==   definitely lost: %s bytes in %i blocks',[1 Inf]);
+					total   = total+ str2num(strrep(char(Numbers(2:end-1)),',',''));
+				end
+				if total==0,
+					disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind'],id,id_string));
+				else
+					disp(sprintf(['ERROR   difference: %i > 0 test id: %i test name: %s field: valgrind'],total,id,id_string));
+					disp('STOP');
+					return;
+				end
+			end
+
 		%ELSE: CHECK TEST
 		else,
