Changeset 579


Ignore:
Timestamp:
May 14, 2023, 10:08:17 PM (20 months ago)
Author:
katerina
Message:

Fix for ticket #467 (memleak).

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/config.h.in

    r576 r579  
    690690#undef HAVE_MEMMOVE
    691691
    692 /* Define to 1 if you have the <memory.h> header file. */
    693 #undef HAVE_MEMORY_H
    694 
    695692/* Define to 1 if you have the `memset' function. */
    696693#undef HAVE_MEMSET
     
    824821/* Define to 1 if you have the <stdint.h> header file. */
    825822#undef HAVE_STDINT_H
     823
     824/* Define to 1 if you have the <stdio.h> header file. */
     825#undef HAVE_STDIO_H
    826826
    827827/* Define to 1 if you have the <stdlib.h> header file. */
     
    926926#undef HAVE_SYS_SYSMACROS_H
    927927
     928/* Define to 1 if you have the <sys/time.h> header file. */
     929#undef HAVE_SYS_TIME_H
     930
    928931/* Define to 1 if you have the <sys/types.h> header file. */
    929932#undef HAVE_SYS_TYPES_H
     
    10701073#undef STAT_MACROS_BROKEN
    10711074
    1072 /* Define to 1 if you have the ANSI C header files. */
     1075/* Define to 1 if all of the C90 standard headers exist (not just the ones
     1076   required in a freestanding environment). This macro is provided for
     1077   backward compatibility; new code need not use it. */
    10731078#undef STDC_HEADERS
    10741079
     
    10821087#undef TIGER_OPT_ASM
    10831088
    1084 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
     1089/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. This
     1090   macro is obsolete. */
    10851091#undef TIME_WITH_SYS_TIME
    10861092
     
    11241130#endif
    11251131
    1126 /* Enable large inode numbers on Mac OS X 10.5.  */
    1127 #ifndef _DARWIN_USE_64_BIT_INODE
    1128 # define _DARWIN_USE_64_BIT_INODE 1
    1129 #endif
    1130 
    11311132/* Number of bits in a file offset, on hosts where this is settable. */
    11321133#undef _FILE_OFFSET_BITS
     
    11521153/* Define to the equivalent of the C99 'restrict' keyword, or to
    11531154   nothing if this is not supported.  Do not define if restrict is
    1154    supported directly.  */
     1155   supported only directly.  */
    11551156#undef restrict
    1156 /* Work around a bug in Sun C++: it does not support _Restrict or
    1157    __restrict__, even though the corresponding Sun C compiler ends up with
    1158    "#define restrict _Restrict" or "#define restrict __restrict__" in the
    1159    previous line.  Perhaps some future version of Sun C++ will work with
    1160    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
    1161 #if defined __SUNPRO_CC && !defined __RESTRICT
     1157/* Work around a bug in older versions of Sun C++, which did not
     1158   #define __restrict__ or support _Restrict or __restrict__
     1159   even though the corresponding Sun C compiler ended up with
     1160   "#define restrict _Restrict" or "#define restrict __restrict__"
     1161   in the previous line.  This workaround can be removed once
     1162   we assume Oracle Developer Studio 12.5 (2016) or later.  */
     1163#if defined __SUNPRO_CC && !defined __RESTRICT && !defined __restrict__
    11621164# define _Restrict
    11631165# define __restrict__
  • trunk/configure.ac

    r578 r579  
    1212dnl start
    1313dnl
    14 AM_INIT_AUTOMAKE(samhain, 4.4.9)
     14AM_INIT_AUTOMAKE(samhain, 4.4.10)
    1515AC_DEFINE([SAMHAIN], 1, [Application is samhain])
    1616AC_CANONICAL_HOST
     
    17111711                fi
    17121712                mydebugit="yes"
     1713        elif test "x${enable_debug}" = "xmem"; then
     1714                AC_DEFINE(MEM_DEBUG)
     1715                AC_DEFINE(SH_ABORT_ON_ERROR, 1, [Use abort])
     1716                if test "x${myneedg3}" = "xyes"; then
     1717                        mydebugdef="-g3"
     1718                else
     1719                        mydebugdef="-g"
     1720                fi
     1721                mydebugit="yes"
    17131722        elif test "x${enable_debug}" = "xgdb"; then
    17141723                AC_DEFINE(SH_ABORT_ON_ERROR, 1, [Use abort])
  • trunk/docs/Changelog

    r578 r579  
     14.4.10:
     2        * fix for (very minor) memleak in sh_unix.c: sh_check_rotated_log()
     3        * fix for memleak in sh_files.c: sh_files_checkdir(), not all cases for
     4        scandir() covered (issue reported by T. Greulich)
     5
    164.4.9:
    27        * fix for double newline stripping when reading from database
  • trunk/src/samhain.c

    r550 r579  
    777777  sh_hash_hashdelete();
    778778  sh_files_hle_reg (NULL);
     779  (void) sh_ignore_clean ();
    779780  /*
    780781   * Only flush on exit if running as deamon.
  • trunk/src/sh_dbIO.c

    r578 r579  
    14151415    lpath = ll;
    14161416  else
     1417    /* cppcheck-suppress uninitvar */
    14171418    lpath = linkpath;
    14181419
  • trunk/src/sh_files.c

    r565 r579  
    23152315            {
    23162316              ++theDir->NumDirs;
     2317#if defined(SH_USE_SCANDIR)
     2318              free(entryList[entry]); /* scandir() mallocs entries */
     2319#endif
    23172320              continue;
    23182321            }
     
    23202323            {
    23212324              ++theDir->NumDirs;
     2325#if defined(SH_USE_SCANDIR)
     2326              free(entryList[entry]); /* scandir() mallocs entries */
     2327#endif
    23222328              continue;
    23232329            }
  • trunk/src/sh_mem.c

    r516 r579  
    7777#endif
    7878
    79 /* define MEM_LOG to an absolute filename to enable this */
     79/* define MEM_LOG to enable this */
     80/* #define MEM_LOG 1 */
    8081#ifdef MEM_LOG
    8182void sh_mem_dump ()
     
    8384  memlist_t   * this = memlist;
    8485  FILE * fd;
    85 
     86  static unsigned int nr = 0;
     87  char filename[256];
     88
     89  snprintf(filename, sizeof(filename), "sh_mem_dump.%04u.%lu", nr, (unsigned long) sh.pid);
     90 
    8691  SH_MUTEX_RECURSIVE_INIT(mutex_mem);
    8792  SH_MUTEX_RECURSIVE_LOCK(mutex_mem);
    8893
    89   fd = fopen(MEM_LOG, "w");
     94  fd = fopen(filename, "w");
    9095  if (!fd)
    9196    {
    92       perror(MEM_LOG);
     97      perror(filename);
    9398      _exit(EXIT_FAILURE);
    9499    }
     
    103108
    104109  SH_MUTEX_RECURSIVE_UNLOCK(mutex_mem);
    105   _exit(EXIT_SUCCESS);
     110  ++nr;
     111  /* _exit(EXIT_SUCCESS); */
     112  return;
    106113}
    107114#else
  • trunk/src/sh_sig.c

    r571 r579  
    16951695#elif defined(WITH_SIGNIFY)
    16961696  return sh_signify_check_signature (file, what);
     1697#else
     1698  return -1;
    16971699#endif
    16981700}
     
    17041706#elif defined(WITH_SIGNIFY)
    17051707  return sh_signify_extract_signed(fd, SIG_DATASIG);
     1708#else
     1709  return -1;
    17061710#endif
    17071711}
     
    17131717#elif defined(WITH_SIGNIFY)
    17141718  return sh_signify_extract_signed(fd, SIG_DATAONLY);
     1719#else
     1720  return -1;
    17151721#endif
    17161722}
     
    17221728#elif defined(WITH_SIGNIFY)
    17231729  return sh_signify_msg_start(line);
     1730#else
     1731  return -1;
    17241732#endif
    17251733}
     
    17311739#elif defined(WITH_SIGNIFY)
    17321740  return sh_signify_msg_startdata(line);
     1741#else
     1742  return -1;
    17331743#endif
    17341744}
     
    17401750#elif defined(WITH_SIGNIFY)
    17411751  return sh_signify_msg_end(line);
     1752#else
     1753  return -1;
    17421754#endif
    17431755}
     
    17491761#elif defined(WITH_SIGNIFY)
    17501762  return sh_signify_data_end(line);
     1763#else
     1764  return -1;
    17511765#endif
    17521766}
  • trunk/src/sh_unix.c

    r570 r579  
    36033603              }
    36043604            }
    3605           SH_FREE(rotated_file);
    3606         }
     3605        }
     3606      if (rotated_file) {
     3607        SH_FREE(rotated_file);
     3608      }
    36073609    }
    36083610  return retval;
     
    48724874  if (0 == retry_lstat(FIL__, __LINE__, path, &buf))
    48734875    SL_RETURN( S_TRUE,   _("sh_unix_file_exists"));
    4874   else
    4875     SL_RETURN( S_FALSE,  _("sh_unix_file_exists"));
     4876
     4877  SL_RETURN( S_FALSE,  _("sh_unix_file_exists"));
    48764878}
    48774879
     
    48884890  if (retry_fstat(FIL__, __LINE__, fd, &buf) == -1)
    48894891    SL_RETURN( (-1), _("sh_unix_device_readable"));
    4890   else if ( S_ISCHR(buf.st_mode) &&  0 != (S_IROTH & buf.st_mode) )
     4892  if ( S_ISCHR(buf.st_mode) &&  0 != (S_IROTH & buf.st_mode) )
    48914893    SL_RETURN( (0), _("sh_unix_device_readable"));
    4892   else
    4893     SL_RETURN( (-1), _("sh_unix_device_readable"));
     4894
     4895  SL_RETURN( (-1), _("sh_unix_device_readable"));
    48944896}
    48954897
Note: See TracChangeset for help on using the changeset viewer.