summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--channels/chan_mgcp.c4
-rw-r--r--main/astfd.c57
-rw-r--r--main/channel_internal_api.c11
-rw-r--r--main/config.c1
-rw-r--r--main/rtp_engine.c4
-rw-r--r--main/sorcery.c4
-rw-r--r--res/res_timing_kqueue.c4
-rw-r--r--res/res_timing_timerfd.c5
8 files changed, 63 insertions, 27 deletions
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index 16d3c6550..d9e182cc7 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -5007,7 +5007,9 @@ static int unload_module(void)
return -1;
}
- close(mgcpsock);
+ if (mgcpsock > -1) {
+ close(mgcpsock);
+ }
ast_rtp_glue_unregister(&mgcp_rtp_glue);
ast_cli_unregister_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry));
ast_sched_context_destroy(sched);
diff --git a/main/astfd.c b/main/astfd.c
index 72c5761d7..746737669 100644
--- a/main/astfd.c
+++ b/main/astfd.c
@@ -48,19 +48,24 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/unaligned.h"
static struct fdleaks {
- char file[40];
+ const char *callname;
int line;
+ unsigned int isopen:1;
+ char file[40];
char function[25];
- char callname[10];
char callargs[60];
- unsigned int isopen:1;
} fdleaks[1024] = { { "", }, };
+/* COPY does ast_copy_string(dst, src, sizeof(dst)), except:
+ * - if it doesn't fit, it copies the value after the slash
+ * (possibly truncated)
+ * - if there is no slash, it copies the value with the head
+ * truncated */
#define COPY(dst, src) \
do { \
int dlen = sizeof(dst), slen = strlen(src); \
if (slen + 1 > dlen) { \
- char *slash = strrchr(src, '/'); \
+ const char *slash = strrchr(src, '/'); \
if (slash) { \
ast_copy_string(dst, slash + 1, dlen); \
} else { \
@@ -72,12 +77,15 @@ static struct fdleaks {
} while (0)
#define STORE_COMMON(offset, name, ...) \
- COPY(fdleaks[offset].file, file); \
- fdleaks[offset].line = line; \
- COPY(fdleaks[offset].function, func); \
- strcpy(fdleaks[offset].callname, name); \
- snprintf(fdleaks[offset].callargs, sizeof(fdleaks[offset].callargs), __VA_ARGS__); \
- fdleaks[offset].isopen = 1;
+ do { \
+ struct fdleaks *tmp = &fdleaks[offset]; \
+ COPY(tmp->file, file); \
+ tmp->line = line; \
+ COPY(tmp->function, func); \
+ tmp->callname = name; \
+ snprintf(tmp->callargs, sizeof(tmp->callargs), __VA_ARGS__); \
+ tmp->isopen = 1; \
+ } while (0)
#undef open
int __ast_fdleak_open(const char *file, int line, const char *func, const char *path, int flags, ...)
@@ -91,7 +99,7 @@ int __ast_fdleak_open(const char *file, int line, const char *func, const char *
mode = va_arg(ap, int);
va_end(ap);
res = open(path, flags, mode);
- if (res > -1 && res < (sizeof(fdleaks) / sizeof(fdleaks[0]))) {
+ if (res > -1 && res < ARRAY_LEN(fdleaks)) {
char sflags[80];
snprintf(sflags, sizeof(sflags), "O_CREAT%s%s%s%s%s%s%s%s",
flags & O_APPEND ? "|O_APPEND" : "",
@@ -115,7 +123,7 @@ int __ast_fdleak_open(const char *file, int line, const char *func, const char *
}
} else {
res = open(path, flags);
- if (res > -1 && res < (sizeof(fdleaks) / sizeof(fdleaks[0]))) {
+ if (res > -1 && res < ARRAY_LEN(fdleaks)) {
STORE_COMMON(res, "open", "\"%s\",%d", path, flags);
}
}
@@ -130,7 +138,9 @@ int __ast_fdleak_pipe(int *fds, const char *file, int line, const char *func)
return res;
}
for (i = 0; i < 2; i++) {
- STORE_COMMON(fds[i], "pipe", "{%d,%d}", fds[0], fds[1]);
+ if (fds[i] > -1 && fds[i] < ARRAY_LEN(fdleaks)) {
+ STORE_COMMON(fds[i], "pipe", "{%d,%d}", fds[0], fds[1]);
+ }
}
return 0;
}
@@ -141,7 +151,7 @@ int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, in
char sdomain[20], stype[20], *sproto = NULL;
struct protoent *pe;
int res = socket(domain, type, protocol);
- if (res < 0 || res > 1023) {
+ if (res < 0 || res >= ARRAY_LEN(fdleaks)) {
return res;
}
@@ -183,7 +193,7 @@ int __ast_fdleak_socket(int domain, int type, int protocol, const char *file, in
int __ast_fdleak_close(int fd)
{
int res = close(fd);
- if (!res && fd > -1 && fd < 1024) {
+ if (!res && fd > -1 && fd < ARRAY_LEN(fdleaks)) {
fdleaks[fd].isopen = 0;
}
return res;
@@ -198,7 +208,9 @@ FILE *__ast_fdleak_fopen(const char *path, const char *mode, const char *file, i
return res;
}
fd = fileno(res);
- STORE_COMMON(fd, "fopen", "\"%s\",\"%s\"", path, mode);
+ if (fd > -1 && fd < ARRAY_LEN(fdleaks)) {
+ STORE_COMMON(fd, "fopen", "\"%s\",\"%s\"", path, mode);
+ }
return res;
}
@@ -211,7 +223,7 @@ int __ast_fdleak_fclose(FILE *ptr)
}
fd = fileno(ptr);
- if ((res = fclose(ptr)) || fd < 0 || fd > 1023) {
+ if ((res = fclose(ptr)) || fd < 0 || fd >= ARRAY_LEN(fdleaks)) {
return res;
}
fdleaks[fd].isopen = 0;
@@ -222,10 +234,13 @@ int __ast_fdleak_fclose(FILE *ptr)
int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const char *func)
{
int res = dup2(oldfd, newfd);
- if (res < 0 || res > 1023) {
+ if (res < 0 || res >= ARRAY_LEN(fdleaks)) {
return res;
}
- STORE_COMMON(res, "dup2", "%d,%d", oldfd, newfd);
+ /* On success, newfd will be closed automatically if it was already
+ * open. We don't need to mention anything about that, we're updating
+ * the value anway. */
+ STORE_COMMON(res, "dup2", "%d,%d", oldfd, newfd); /* res == newfd */
return res;
}
@@ -233,7 +248,7 @@ int __ast_fdleak_dup2(int oldfd, int newfd, const char *file, int line, const ch
int __ast_fdleak_dup(int oldfd, const char *file, int line, const char *func)
{
int res = dup(oldfd);
- if (res < 0 || res > 1023) {
+ if (res < 0 || res >= ARRAY_LEN(fdleaks)) {
return res;
}
STORE_COMMON(res, "dup2", "%d", oldfd);
@@ -263,7 +278,7 @@ static char *handle_show_fd(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
snprintf(line, sizeof(line), "%d/%d", (int) rl.rlim_cur, (int) rl.rlim_max);
}
ast_cli(a->fd, "Current maxfiles: %s\n", line);
- for (i = 0; i < 1024; i++) {
+ for (i = 0; i < ARRAY_LEN(fdleaks); i++) {
if (fdleaks[i].isopen) {
snprintf(line, sizeof(line), "%d", fdleaks[i].line);
ast_cli(a->fd, "%5d %15s:%-7.7s (%-25s): %s(%s)\n", i, fdleaks[i].file, line, fdleaks[i].function, fdleaks[i].callname, fdleaks[i].callargs);
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index 0bb38499b..987602db6 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -1202,7 +1202,14 @@ void ast_channel_named_pickupgroups_set(struct ast_channel *chan, struct ast_nam
int ast_channel_alert_write(struct ast_channel *chan)
{
char blah = 0x7F;
- return ast_channel_alert_writable(chan) && write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
+
+ if (!ast_channel_alert_writable(chan)) {
+ errno = EBADF;
+ return 0;
+ }
+ /* preset errno in case returned size does not match */
+ errno = EPIPE;
+ return write(chan->alertpipe[1], &blah, sizeof(blah)) != sizeof(blah);
}
ast_alert_status_t ast_channel_internal_alert_read(struct ast_channel *chan)
@@ -1253,9 +1260,11 @@ void ast_channel_internal_alertpipe_close(struct ast_channel *chan)
{
if (ast_channel_internal_alert_readable(chan)) {
close(chan->alertpipe[0]);
+ chan->alertpipe[0] = -1;
}
if (ast_channel_alert_writable(chan)) {
close(chan->alertpipe[1]);
+ chan->alertpipe[1] = -1;
}
}
diff --git a/main/config.c b/main/config.c
index d6a077b2d..008abffdf 100644
--- a/main/config.c
+++ b/main/config.c
@@ -2869,6 +2869,7 @@ int ast_realtime_is_mapping_defined(const char *family)
return 1;
}
}
+ ast_debug(5, "Failed to find a realtime mapping for %s\n", family);
return 0;
}
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index 88d2db3d0..6ae8faf9c 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -1798,7 +1798,9 @@ int ast_rtp_engine_unload_format(struct ast_format *format)
rtp_engine_mime_type_cleanup(x);
continue;
}
- ast_rtp_mime_types[y] = ast_rtp_mime_types[x];
+ if (x != y) {
+ ast_rtp_mime_types[y] = ast_rtp_mime_types[x];
+ }
y++;
}
mime_types_len = y;
diff --git a/main/sorcery.c b/main/sorcery.c
index 1ff83de66..20b3d6b2f 100644
--- a/main/sorcery.c
+++ b/main/sorcery.c
@@ -991,7 +991,11 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor
}
}
+ ast_debug(5, "Calling wizard %s open callback on object type %s\n",
+ name, object_type->name);
if (wizard->callbacks.open && !(object_wizard->data = wizard->callbacks.open(data))) {
+ ast_log(LOG_WARNING, "Wizard '%s' failed to open mapping for object type '%s' with data: %s\n",
+ name, object_type->name, S_OR(data, ""));
AST_VECTOR_RW_UNLOCK(&object_type->wizards);
return AST_SORCERY_APPLY_FAIL;
}
diff --git a/res/res_timing_kqueue.c b/res/res_timing_kqueue.c
index dd2a8397c..f568144aa 100644
--- a/res/res_timing_kqueue.c
+++ b/res/res_timing_kqueue.c
@@ -159,7 +159,9 @@ static void timer_destroy(void *obj)
struct kqueue_timer *timer = obj;
ast_debug(5, "[%d]: Timer Destroy\n", timer->handle);
kqueue_timer_fini_continuous_event(timer);
- close(timer->handle);
+ if (timer->handle > -1) {
+ close(timer->handle);
+ }
}
static void *kqueue_timer_open(void)
diff --git a/res/res_timing_timerfd.c b/res/res_timing_timerfd.c
index 5ee21fcc0..71f74bb03 100644
--- a/res/res_timing_timerfd.c
+++ b/res/res_timing_timerfd.c
@@ -76,8 +76,9 @@ struct timerfd_timer {
static void timer_destroy(void *obj)
{
struct timerfd_timer *timer = obj;
-
- close(timer->fd);
+ if (timer->fd > -1) {
+ close(timer->fd);
+ }
}
static void *timerfd_timer_open(void)