diff options
-rw-r--r-- | Makefile.moddir_rules | 5 | ||||
-rw-r--r-- | channels/Makefile | 1 | ||||
-rw-r--r-- | channels/chan_mgcp.c | 4 | ||||
-rw-r--r-- | channels/chan_sip.c | 2 | ||||
-rw-r--r-- | channels/chan_vpb.cc | 5 | ||||
-rw-r--r-- | channels/misdn/Makefile | 2 | ||||
-rw-r--r-- | main/astfd.c | 57 | ||||
-rw-r--r-- | main/channel_internal_api.c | 11 | ||||
-rw-r--r-- | main/config.c | 1 | ||||
-rw-r--r-- | main/dns_recurring.c | 24 | ||||
-rw-r--r-- | main/rtp_engine.c | 4 | ||||
-rw-r--r-- | main/sorcery.c | 4 | ||||
-rw-r--r-- | res/res_sorcery_memory_cache.c | 5 | ||||
-rw-r--r-- | res/res_timing_kqueue.c | 4 | ||||
-rw-r--r-- | res/res_timing_timerfd.c | 5 |
15 files changed, 91 insertions, 43 deletions
diff --git a/Makefile.moddir_rules b/Makefile.moddir_rules index e7022822d..df715d987 100644 --- a/Makefile.moddir_rules +++ b/Makefile.moddir_rules @@ -81,8 +81,8 @@ clean-$(1)$(3): endef -MOD_ADD_C=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.c,.i,.o)) -MOD_ADD_CC=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.cc,.ii,.oo)) +MOD_ADD_C=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.c,.i,.o,.gcda,.gcno)) +MOD_ADD_CC=$(eval $(call MOD_ADD_SOURCE,$(1),$(2),.cc,.ii,.oo,.gcda,.gcno)) $(addsuffix .oo,$(CC_MODS)) $(addsuffix .o,$(C_MODS)): \ _ASTCFLAGS+=$(call MOD_ASTCFLAGS,$*) @@ -140,6 +140,7 @@ clean:: rm -f *.so *.o *.oo *.eo *.i *.ii rm -f .*.d rm -f *.s *.i + rm -f *.gcda *.gcno rm -f modules.link install:: all diff --git a/channels/Makefile b/channels/Makefile index 733ce4111..44a0429a9 100644 --- a/channels/Makefile +++ b/channels/Makefile @@ -23,7 +23,6 @@ ifneq ($(findstring $(OSARCH), mingw32 cygwin ),) LIBS+= -lres_monitor.so endif - $(call MOD_ADD_C,chan_iax2,$(wildcard iax2/*.c)) $(call MOD_ADD_C,chan_sip,$(wildcard sip/*.c)) $(call MOD_ADD_C,chan_pjsip,$(wildcard pjsip/*.c)) 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/channels/chan_sip.c b/channels/chan_sip.c index 96609d218..412a25764 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -24926,10 +24926,12 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, if (ast_bridge_impart(bridge, c, replaces_chan, NULL, AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) { ast_hangup(c); + ast_channel_unref(c); } } else { ast_channel_move(replaces_chan, c); ast_hangup(c); + ast_channel_unref(c); } sip_pvt_lock(p); return 0; diff --git a/channels/chan_vpb.cc b/channels/chan_vpb.cc index 16a66b908..7cdcf303a 100644 --- a/channels/chan_vpb.cc +++ b/channels/chan_vpb.cc @@ -2628,14 +2628,13 @@ static int unload_module(void) if (bridges) { ast_mutex_lock(&bridge_lock); - memset(bridges, 0, sizeof bridges); - ast_mutex_unlock(&bridge_lock); - ast_mutex_destroy(&bridge_lock); for (int i = 0; i < max_bridges; i++) { ast_mutex_destroy(&bridges[i].lock); ast_cond_destroy(&bridges[i].cond); } ast_free(bridges); + bridges = NULL; + ast_mutex_unlock(&bridge_lock); } ao2_cleanup(vpb_tech.capabilities); diff --git a/channels/misdn/Makefile b/channels/misdn/Makefile index 194bef5ae..96d5a2a3d 100644 --- a/channels/misdn/Makefile +++ b/channels/misdn/Makefile @@ -14,4 +14,4 @@ portinfo: portinfo.o $(CC) -o $@ $^ -lisdnnet -lmISDN -lpthread clean: - rm -rf *.a *.o *.so portinfo *.i + rm -rf *.a *.o *.so portinfo *.i *.gcda *.gcno 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/dns_recurring.c b/main/dns_recurring.c index 855273f10..992575507 100644 --- a/main/dns_recurring.c +++ b/main/dns_recurring.c @@ -73,10 +73,21 @@ static int dns_query_recurring_scheduled_callback(const void *data) static void dns_query_recurring_resolution_callback(const struct ast_dns_query *query) { struct ast_dns_query_recurring *recurring = ast_dns_query_get_data(query); - - /* Replace the user data so the actual callback sees what it provided */ - ((struct ast_dns_query*)query)->user_data = ao2_bump(recurring->user_data); - recurring->callback(query); + struct ast_dns_query *callback_query; + + /* Create a separate query to invoke the user specific callback on as the + * recurring query user data may get used externally (by the unit test) + * and thus changing it is problematic + */ + callback_query = dns_query_alloc(query->name, query->rr_type, query->rr_class, + recurring->callback, recurring->user_data); + if (callback_query) { + /* The result is immutable at this point and can be safely provided */ + callback_query->result = query->result; + callback_query->callback(callback_query); + callback_query->result = NULL; + ao2_ref(callback_query, -1); + } ao2_lock(recurring); /* So.. if something has not externally cancelled this we can reschedule based on the TTL */ @@ -87,7 +98,7 @@ static void dns_query_recurring_resolution_callback(const struct ast_dns_query * if (ttl) { recurring->timer = ast_sched_add(ast_dns_get_sched(), ttl * 1000, dns_query_recurring_scheduled_callback, ao2_bump(recurring)); if (recurring->timer < 0) { - /* It is impossible for this to be the last reference as this callback function holds a reference itself */ + /* It is impossible for this to be the last reference as the query has a reference to it */ ao2_ref(recurring, -1); } } @@ -95,9 +106,6 @@ static void dns_query_recurring_resolution_callback(const struct ast_dns_query * ao2_replace(recurring->active, NULL); ao2_unlock(recurring); - - /* Since we stole the reference from the query we need to drop it ourselves */ - ao2_ref(recurring, -1); } struct ast_dns_query_recurring *ast_dns_resolve_recurring(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data) 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_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c index 7a07d14f0..e486a6400 100644 --- a/res/res_sorcery_memory_cache.c +++ b/res/res_sorcery_memory_cache.c @@ -2551,6 +2551,10 @@ static int load_module(void) return AST_MODULE_LOAD_DECLINE; } + /* This causes the stale unit test to execute last, so if a sorcery instance persists + * longer than expected subsequent unit tests don't fail when setting it up. + */ + AST_TEST_REGISTER(stale); AST_TEST_REGISTER(open_with_valid_options); AST_TEST_REGISTER(open_with_invalid_options); AST_TEST_REGISTER(create_and_retrieve); @@ -2558,7 +2562,6 @@ static int load_module(void) AST_TEST_REGISTER(delete); AST_TEST_REGISTER(maximum_objects); AST_TEST_REGISTER(expiration); - AST_TEST_REGISTER(stale); return AST_MODULE_LOAD_SUCCESS; } 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) |