Index: trunk/config.h.in
===================================================================
--- trunk/config.h.in	(revision 578)
+++ trunk/config.h.in	(revision 579)
@@ -690,7 +690,4 @@
 #undef HAVE_MEMMOVE
 
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
 /* Define to 1 if you have the `memset' function. */
 #undef HAVE_MEMSET
@@ -824,4 +821,7 @@
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#undef HAVE_STDIO_H
 
 /* Define to 1 if you have the <stdlib.h> header file. */
@@ -926,4 +926,7 @@
 #undef HAVE_SYS_SYSMACROS_H
 
+/* Define to 1 if you have the <sys/time.h> header file. */
+#undef HAVE_SYS_TIME_H
+
 /* Define to 1 if you have the <sys/types.h> header file. */
 #undef HAVE_SYS_TYPES_H
@@ -1070,5 +1073,7 @@
 #undef STAT_MACROS_BROKEN
 
-/* Define to 1 if you have the ANSI C header files. */
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
 #undef STDC_HEADERS
 
@@ -1082,5 +1087,6 @@
 #undef TIGER_OPT_ASM
 
-/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
+/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. This
+   macro is obsolete. */
 #undef TIME_WITH_SYS_TIME
 
@@ -1124,9 +1130,4 @@
 #endif
 
-/* Enable large inode numbers on Mac OS X 10.5.  */
-#ifndef _DARWIN_USE_64_BIT_INODE
-# define _DARWIN_USE_64_BIT_INODE 1
-#endif
-
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS
@@ -1152,12 +1153,13 @@
 /* Define to the equivalent of the C99 'restrict' keyword, or to
    nothing if this is not supported.  Do not define if restrict is
-   supported directly.  */
+   supported only directly.  */
 #undef restrict
-/* Work around a bug in Sun C++: it does not support _Restrict or
-   __restrict__, even though the corresponding Sun C compiler ends up with
-   "#define restrict _Restrict" or "#define restrict __restrict__" in the
-   previous line.  Perhaps some future version of Sun C++ will work with
-   restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
-#if defined __SUNPRO_CC && !defined __RESTRICT
+/* Work around a bug in older versions of Sun C++, which did not
+   #define __restrict__ or support _Restrict or __restrict__
+   even though the corresponding Sun C compiler ended up with
+   "#define restrict _Restrict" or "#define restrict __restrict__"
+   in the previous line.  This workaround can be removed once
+   we assume Oracle Developer Studio 12.5 (2016) or later.  */
+#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
 # define _Restrict
 # define __restrict__
Index: trunk/configure.ac
===================================================================
--- trunk/configure.ac	(revision 578)
+++ trunk/configure.ac	(revision 579)
@@ -12,5 +12,5 @@
 dnl start
 dnl
-AM_INIT_AUTOMAKE(samhain, 4.4.9)
+AM_INIT_AUTOMAKE(samhain, 4.4.10)
 AC_DEFINE([SAMHAIN], 1, [Application is samhain])
 AC_CANONICAL_HOST
@@ -1711,4 +1711,13 @@
                 fi
                 mydebugit="yes"
+	elif test "x${enable_debug}" = "xmem"; then
+                AC_DEFINE(MEM_DEBUG)
+		AC_DEFINE(SH_ABORT_ON_ERROR, 1, [Use abort])
+                if test "x${myneedg3}" = "xyes"; then
+                        mydebugdef="-g3"
+                else
+                        mydebugdef="-g"
+                fi
+		mydebugit="yes"
 	elif test "x${enable_debug}" = "xgdb"; then
 	     	AC_DEFINE(SH_ABORT_ON_ERROR, 1, [Use abort])
Index: trunk/docs/Changelog
===================================================================
--- trunk/docs/Changelog	(revision 578)
+++ trunk/docs/Changelog	(revision 579)
@@ -1,2 +1,7 @@
+4.4.10:
+	* fix for (very minor) memleak in sh_unix.c: sh_check_rotated_log()
+	* fix for memleak in sh_files.c: sh_files_checkdir(), not all cases for
+	scandir() covered (issue reported by T. Greulich)
+
 4.4.9:
 	* fix for double newline stripping when reading from database
Index: trunk/src/samhain.c
===================================================================
--- trunk/src/samhain.c	(revision 578)
+++ trunk/src/samhain.c	(revision 579)
@@ -777,4 +777,5 @@
   sh_hash_hashdelete();
   sh_files_hle_reg (NULL);
+  (void) sh_ignore_clean ();
   /*
    * Only flush on exit if running as deamon.
Index: trunk/src/sh_dbIO.c
===================================================================
--- trunk/src/sh_dbIO.c	(revision 578)
+++ trunk/src/sh_dbIO.c	(revision 579)
@@ -1415,4 +1415,5 @@
     lpath = ll;
   else
+    /* cppcheck-suppress uninitvar */
     lpath = linkpath;
 
Index: trunk/src/sh_files.c
===================================================================
--- trunk/src/sh_files.c	(revision 578)
+++ trunk/src/sh_files.c	(revision 579)
@@ -2315,4 +2315,7 @@
 	    { 
 	      ++theDir->NumDirs;
+#if defined(SH_USE_SCANDIR)
+	      free(entryList[entry]); /* scandir() mallocs entries */
+#endif
 	      continue;
 	    }
@@ -2320,4 +2323,7 @@
 	    {
 	      ++theDir->NumDirs;
+#if defined(SH_USE_SCANDIR)
+	      free(entryList[entry]); /* scandir() mallocs entries */
+#endif
 	      continue;
 	    }
Index: trunk/src/sh_mem.c
===================================================================
--- trunk/src/sh_mem.c	(revision 578)
+++ trunk/src/sh_mem.c	(revision 579)
@@ -77,5 +77,6 @@
 #endif
 
-/* define MEM_LOG to an absolute filename to enable this */
+/* define MEM_LOG to enable this */
+/* #define MEM_LOG 1 */
 #ifdef MEM_LOG
 void sh_mem_dump ()
@@ -83,12 +84,16 @@
   memlist_t   * this = memlist;
   FILE * fd;
-
+  static unsigned int nr = 0;
+  char filename[256];
+
+  snprintf(filename, sizeof(filename), "sh_mem_dump.%04u.%lu", nr, (unsigned long) sh.pid);
+  
   SH_MUTEX_RECURSIVE_INIT(mutex_mem);
   SH_MUTEX_RECURSIVE_LOCK(mutex_mem);
 
-  fd = fopen(MEM_LOG, "w");
+  fd = fopen(filename, "w");
   if (!fd)
     {
-      perror(MEM_LOG);
+      perror(filename);
       _exit(EXIT_FAILURE);
     }
@@ -103,5 +108,7 @@
 
   SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem);
-  _exit(EXIT_SUCCESS);
+  ++nr;
+  /* _exit(EXIT_SUCCESS); */
+  return;
 }
 #else
Index: trunk/src/sh_sig.c
===================================================================
--- trunk/src/sh_sig.c	(revision 578)
+++ trunk/src/sh_sig.c	(revision 579)
@@ -1695,4 +1695,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_check_signature (file, what);
+#else
+  return -1;
 #endif
 }
@@ -1704,4 +1706,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_extract_signed(fd, SIG_DATASIG);
+#else
+  return -1;
 #endif
 }
@@ -1713,4 +1717,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_extract_signed(fd, SIG_DATAONLY);
+#else
+  return -1;
 #endif
 }
@@ -1722,4 +1728,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_msg_start(line);
+#else
+  return -1;
 #endif
 }
@@ -1731,4 +1739,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_msg_startdata(line);
+#else
+  return -1;
 #endif
 }
@@ -1740,4 +1750,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_msg_end(line);
+#else
+  return -1;
 #endif
 }
@@ -1749,4 +1761,6 @@
 #elif defined(WITH_SIGNIFY)
   return sh_signify_data_end(line);
+#else
+  return -1;
 #endif
 }
Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 578)
+++ trunk/src/sh_unix.c	(revision 579)
@@ -3603,6 +3603,8 @@
 	      }
 	    }
-	  SH_FREE(rotated_file);
-	}
+	}
+      if (rotated_file) {
+	SH_FREE(rotated_file);
+      }
     }
   return retval;
@@ -4872,6 +4874,6 @@
   if (0 == retry_lstat(FIL__, __LINE__, path, &buf))
     SL_RETURN( S_TRUE,   _("sh_unix_file_exists"));
-  else 
-    SL_RETURN( S_FALSE,  _("sh_unix_file_exists"));
+
+  SL_RETURN( S_FALSE,  _("sh_unix_file_exists"));
 }
 
@@ -4888,8 +4890,8 @@
   if (retry_fstat(FIL__, __LINE__, fd, &buf) == -1)
     SL_RETURN( (-1), _("sh_unix_device_readable"));
-  else if ( S_ISCHR(buf.st_mode) &&  0 != (S_IROTH & buf.st_mode) ) 
+  if ( S_ISCHR(buf.st_mode) &&  0 != (S_IROTH & buf.st_mode) ) 
     SL_RETURN( (0), _("sh_unix_device_readable"));
-  else 
-    SL_RETURN( (-1), _("sh_unix_device_readable"));
+
+  SL_RETURN( (-1), _("sh_unix_device_readable"));
 }
 
