<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10729">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, approved; Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Merge malloc_trim patch<br><br>We've had multiple opportunities where Richard Mudgett's<br>malloc_trim patch has been useful. Let's get it<br>pushed up to gerrit and merged.<br><br>Since malloc_trim is only available in libc, an entry is<br>added to configure.ac to create a definition for<br>HAVE_MALLOC_TRIM.<br><br>Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c<br>---<br>M configure<br>M configure.ac<br>M include/asterisk/autoconfig.h.in<br>M main/cli.c<br>4 files changed, 38 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configure b/configure</span><br><span>index faf0781..061845f 100755</span><br><span>--- a/configure</span><br><span>+++ b/configure</span><br><span>@@ -16847,7 +16847,7 @@</span><br><span> done</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-for ac_func in asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl</span><br><span style="color: hsl(120, 100%, 40%);">+for ac_func in asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim</span><br><span> do :</span><br><span>   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`</span><br><span> ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"</span><br><span>diff --git a/configure.ac b/configure.ac</span><br><span>index dd0c8ed..e541e33 100644</span><br><span>--- a/configure.ac</span><br><span>+++ b/configure.ac</span><br><span>@@ -784,7 +784,7 @@</span><br><span> AC_FUNC_STRTOD</span><br><span> AC_FUNC_UTIME_NULL</span><br><span> AC_FUNC_VPRINTF</span><br><span style="color: hsl(0, 100%, 40%);">-AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl])</span><br><span style="color: hsl(120, 100%, 40%);">+AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim])</span><br><span> </span><br><span> AC_MSG_CHECKING(for htonll)</span><br><span> AC_LINK_IFELSE(</span><br><span>diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in</span><br><span>index 30bb907..d0141fb 100644</span><br><span>--- a/include/asterisk/autoconfig.h.in</span><br><span>+++ b/include/asterisk/autoconfig.h.in</span><br><span>@@ -492,6 +492,9 @@</span><br><span> /* Define to 1 if you have the <malloc.h> header file. */</span><br><span> #undef HAVE_MALLOC_H</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Define to 1 if you have the `malloc_trim' function. */</span><br><span style="color: hsl(120, 100%, 40%);">+#undef HAVE_MALLOC_TRIM</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Define to 1 if you have the <math.h> header file. */</span><br><span> #undef HAVE_MATH_H</span><br><span> </span><br><span>diff --git a/main/cli.c b/main/cli.c</span><br><span>index cf51d0d..5a6fdbe 100644</span><br><span>--- a/main/cli.c</span><br><span>+++ b/main/cli.c</span><br><span>@@ -1788,6 +1788,34 @@</span><br><span>       return CLI_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_MALLOC_TRIM</span><br><span style="color: hsl(120, 100%, 40%);">+       /* BUGBUG malloc_trim() is a libc specific function.  Non-portable. */</span><br><span style="color: hsl(120, 100%, 40%);">+        static char *handle_cli_malloc_trim(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+ {</span><br><span style="color: hsl(120, 100%, 40%);">+             extern int malloc_trim(size_t __pad) __THROW;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+               switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+                case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+                        e->command = "malloc trim";</span><br><span style="color: hsl(120, 100%, 40%);">+                      e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+                         "Usage: malloc trim\n"</span><br><span style="color: hsl(120, 100%, 40%);">+                              "       Try to give excess memory back to the OS.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+                       return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+          case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+                    return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+          }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           if (malloc_trim(0)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                 ast_cli(a->fd, "Returned some memory to the OS.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                      ast_cli(a->fd, "No memory returned to the OS.\n");</span><br><span style="color: hsl(120, 100%, 40%);">+               }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+           return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+   }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static char *handle_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);</span><br><span> </span><br><span> static struct ast_cli_entry cli_cli[] = {</span><br><span>@@ -1833,6 +1861,11 @@</span><br><span>         AST_CLI_DEFINE(handle_cli_check_permissions, "Try a permissions config for a user"),</span><br><span> </span><br><span>   AST_CLI_DEFINE(handle_cli_wait_fullybooted, "Wait for Asterisk to be fully booted"),</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_MALLOC_TRIM</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_CLI_DEFINE(handle_cli_malloc_trim, "Return excess memory to the OS"),</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10729">change 10729</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10729"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c </div>
<div style="display:none"> Gerrit-Change-Number: 10729 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Chris Savinovich <csavinovich@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>