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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">DEBUG_FD_LEAKS: Add missing FD creators.<br><br>This adds FD tracking for the following functions:<br>* eventfd<br>* timerfd_create<br>* socketpair<br>* accept<br><br>ASTERISK-27404<br><br>Change-Id: Id6848fe904ade2d34eb39d2a20bd6b223e1111fc<br>---<br>M include/asterisk.h<br>M main/astfd.c<br>2 files changed, 75 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk.h b/include/asterisk.h<br>index 899438b..9122e3a 100644<br>--- a/include/asterisk.h<br>+++ b/include/asterisk.h<br>@@ -59,7 +59,9 @@<br> <br> #define      open(a,...)     __ast_fdleak_open(__FILE__,__LINE__,__PRETTY_FUNCTION__, a, __VA_ARGS__)<br> #define pipe(a)              __ast_fdleak_pipe(a, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br>+#define socketpair(a,b,c,d)       __ast_fdleak_socketpair(a, b, c, d, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br> #define socket(a,b,c)      __ast_fdleak_socket(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br>+#define accept(a,b,c)     __ast_fdleak_accept(a, b, c, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br> #define close(a)  __ast_fdleak_close(a)<br> #define fopen(a,b)      __ast_fdleak_fopen(a, b, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br> #define       fclose(a)       __ast_fdleak_fclose(a)<br>@@ -71,7 +73,21 @@<br> #endif<br> int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...);<br> int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func);<br>+int __ast_fdleak_socketpair(int domain, int type, int protocol, int sv[2],<br>+   const char *file, int line, const char *func);<br> int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func);<br>+int __ast_fdleak_accept(int socket, struct sockaddr *address, socklen_t *address_len,<br>+  const char *file, int line, const char *func);<br>+#if defined(HAVE_EVENTFD)<br>+#include <sys/eventfd.h><br>+#define eventfd(a,b)      __ast_fdleak_eventfd(a,b, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br>+int __ast_fdleak_eventfd(unsigned int initval, int flags, const char *file, int line, const char *func);<br>+#endif<br>+#if defined(HAVE_TIMERFD)<br>+#include <sys/timerfd.h><br>+#define timerfd_create(a,b) __ast_fdleak_timerfd_create(a,b, __FILE__,__LINE__,__PRETTY_FUNCTION__)<br>+int __ast_fdleak_timerfd_create(int clockid, int flags, const char *file, int line, const char *func);<br>+#endif<br> int __ast_fdleak_close(int fd);<br> FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, int line, const char *func);<br> int __ast_fdleak_fclose(FILE *ptr);<br>diff --git a/main/astfd.c b/main/astfd.c<br>index 34cf7bb..e29361e 100644<br>--- a/main/astfd.c<br>+++ b/main/astfd.c<br>@@ -132,6 +132,19 @@<br>        return res;<br> }<br> <br>+#undef accept<br>+int __ast_fdleak_accept(int socket, struct sockaddr *address, socklen_t *address_len,<br>+   const char *file, int line, const char *func)<br>+{<br>+    int res = accept(socket, address, address_len);<br>+<br>+   if (res >= 0) {<br>+           STORE_COMMON(res, "accept", "{%d}", socket);<br>+     }<br>+<br>+ return res;<br>+}<br>+<br> #undef pipe<br> int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func)<br> {<br>@@ -147,6 +160,52 @@<br>    return 0;<br> }<br> <br>+#undef socketpair<br>+int __ast_fdleak_socketpair(int domain, int type, int protocol, int sv[2],<br>+    const char *file, int line, const char *func)<br>+{<br>+    int i, res = socketpair(domain, type, protocol, sv);<br>+ if (res) {<br>+           return res;<br>+  }<br>+    for (i = 0; i < 2; i++) {<br>+         if (sv[i] > -1 && sv[i] < ARRAY_LEN(fdleaks)) {<br>+                        STORE_COMMON(sv[i], "socketpair", "{%d,%d}", sv[0], sv[1]);<br>+              }<br>+    }<br>+    return 0;<br>+}<br>+<br>+#if defined(HAVE_EVENTFD)<br>+#undef eventfd<br>+#include <sys/eventfd.h><br>+int __ast_fdleak_eventfd(unsigned int initval, int flags, const char *file, int line, const char *func)<br>+{<br>+ int res = eventfd(initval, flags);<br>+<br>+        if (res >= 0) {<br>+           STORE_COMMON(res, "eventfd", "{%d}", res);<br>+       }<br>+<br>+ return res;<br>+}<br>+#endif<br>+<br>+#if defined(HAVE_TIMERFD)<br>+#undef timerfd_create<br>+#include <sys/timerfd.h><br>+int __ast_fdleak_timerfd_create(int clockid, int flags, const char *file, int line, const char *func)<br>+{<br>+ int res = timerfd_create(clockid, flags);<br>+<br>+ if (res >= 0) {<br>+           STORE_COMMON(res, "timerfd_create", "{%d}", res);<br>+        }<br>+<br>+ return res;<br>+}<br>+#endif<br>+<br> #undef socket<br> int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, int line, const char *func)<br> {<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7115">change 7115</a>. To unsubscribe, 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/7115"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Id6848fe904ade2d34eb39d2a20bd6b223e1111fc </div>
<div style="display:none"> Gerrit-Change-Number: 7115 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>