Index: trunk/src/samhain.c
===================================================================
--- trunk/src/samhain.c	(revision 432)
+++ trunk/src/samhain.c	(revision 433)
@@ -2023,5 +2023,5 @@
 	  (flag_check_1 == 1 || flag_check_2 == 1))
 	{
-	  sh.flag.inotify |= SH_INOTIFY_INSCAN;
+	  SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_INSCAN; );
 	  /* Refresh list files matching glob patterns.
 	   */
@@ -2088,6 +2088,6 @@
 	  flag_check_2 = 0;
 	  check_done   = 1;
-	  sh.flag.inotify &= ~SH_INOTIFY_INSCAN;
-	  sh.flag.inotify &= ~SH_INOTIFY_DOSCAN;
+	  SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_INSCAN; );
+	  SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_DOSCAN; );
 
 	  (void) sh_prelink_run (NULL, NULL, 0);
Index: trunk/src/sh_fInotify.c
===================================================================
--- trunk/src/sh_fInotify.c	(revision 432)
+++ trunk/src/sh_fInotify.c	(revision 433)
@@ -130,6 +130,6 @@
     {
       /* Init from main thread */
-      sh.flag.inotify |= SH_INOTIFY_DOSCAN;
-      sh.flag.inotify |= SH_INOTIFY_NEEDINIT;
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_DOSCAN;   );
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_NEEDINIT; );
 
       if (0 == sh_pthread_create(sh_threaded_module_run, (void *)arg))
@@ -154,6 +154,6 @@
       /* Reconfigure from main thread */
       /* sh_fInotify_init_internal(); */
-      sh.flag.inotify |= SH_INOTIFY_DOSCAN;
-      sh.flag.inotify |= SH_INOTIFY_NEEDINIT;
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_DOSCAN;   );
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_NEEDINIT; );
       return SH_MOD_THREAD;
     }
@@ -226,8 +226,8 @@
     {
       count = 0; /* Re-expand glob patterns to discover added files. */
-      sh.flag.inotify |= SH_INOTIFY_INSCAN;
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_INSCAN; );
       sh_files_check_globFilePatterns();
-      sh.flag.inotify &= ~SH_INOTIFY_INSCAN;
-      sh.flag.inotify |= SH_INOTIFY_NEEDINIT;
+      SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_INSCAN;  );
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_NEEDINIT; );
     }
 
@@ -396,5 +396,5 @@
    * DOSCAN is finished, hence wouldn't call init().
    */
-  sh.flag.inotify &= ~SH_INOTIFY_NEEDINIT;
+  SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_NEEDINIT; );
 
   return 0;
@@ -474,6 +474,7 @@
   else if ((event->mask & IN_Q_OVERFLOW) != 0)
     {
-      sh.flag.inotify |= SH_INOTIFY_DOSCAN;
-      sh.flag.inotify |= SH_INOTIFY_NEEDINIT;
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_DOSCAN;   );
+      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_NEEDINIT; );
+
       SH_MUTEX_LOCK(mutex_thread_nolog);
       sh_error_handle(SH_ERR_WARN, FIL__, __LINE__, event->wd, MSG_E_SUBGEN, 
@@ -639,9 +640,9 @@
 	  if (event->mask & IN_ISDIR)
 	    {
-	      sh.flag.inotify |= SH_INOTIFY_INSCAN;
+	      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_INSCAN;   );
 	      sh_files_checkdir (classD, check_maskD, rdepthD, 
 				 path, (event->len > 0) ? event->name : NULL);
-	      sh.flag.inotify &= ~SH_INOTIFY_INSCAN;
-	      sh.flag.inotify |= SH_INOTIFY_NEEDINIT;
+	      SH_INOTIFY_IFUSED( sh.flag.inotify &= ~SH_INOTIFY_INSCAN;  );
+	      SH_INOTIFY_IFUSED( sh.flag.inotify |= SH_INOTIFY_NEEDINIT; );
 	      sh_dirs_reset  ();
 	      sh_files_reset ();
Index: trunk/src/sh_files.c
===================================================================
--- trunk/src/sh_files.c	(revision 432)
+++ trunk/src/sh_files.c	(revision 433)
@@ -2010,4 +2010,5 @@
       if (theFile->link_path)   SH_FREE(theFile->link_path);
       SH_FREE(theFile);
+      SH_FREE(tmpname);
       SL_RETURN((0), _("sh_files_checkdir"));
     }
@@ -2015,8 +2016,8 @@
   if (status == -1)
     {
-      SH_FREE(tmpname); 
       if (theFile->attr_string) SH_FREE(theFile->attr_string);
       if (theFile->link_path)   SH_FREE(theFile->link_path);
       SH_FREE(theFile);
+      SH_FREE(tmpname);
       SL_RETURN((-1), _("sh_files_checkdir"));
     }
@@ -2028,8 +2029,8 @@
 		       tmpname);
       ++sh.statistics.files_nodir;
-      SH_FREE(tmpname); 
       if (theFile->attr_string) SH_FREE(theFile->attr_string);
       if (theFile->link_path)   SH_FREE(theFile->link_path);
       SH_FREE(theFile);
+      SH_FREE(tmpname);
       SL_RETURN((-1), _("sh_files_checkdir"));
     }
@@ -2127,4 +2128,5 @@
       {
 	SH_FREE(theDir);
+	SH_FREE(tmpname);
 	SL_RETURN((0), _("sh_files_checkdir"));
       }
@@ -2366,4 +2368,5 @@
 	SH_FREE(theDir);
 	sh_dummy_dirlist = NULL;
+	SH_FREE(tmpname);
 	SL_RETURN((0), _("sh_files_checkdir"));
       }
