Index: res/res_musiconhold.c =================================================================== --- res/res_musiconhold.c (revision 232854) +++ res/res_musiconhold.c (working copy) @@ -50,6 +50,8 @@ #include #endif +#define REF_DEBUG + #include "asterisk/lock.h" #include "asterisk/file.h" #include "asterisk/channel.h" @@ -195,7 +197,27 @@ static int reload(void); #define mohclass_ref(class,string) (ao2_t_ref((class), +1, (string)), class) + +#ifndef REF_DEBUG #define mohclass_unref(class,string) (ao2_t_ref((class), -1, (string)), (struct mohclass *) NULL) +#else +#define mohclass_unref(class,string) _mohclass_unref(class, string, __FILE__,__LINE__,__PRETTY_FUNCTION__) +static struct mohclass *_mohclass_unref(struct mohclass *class, const char *tag, const char *file, int line, const char *funcname) +{ + struct mohclass *dup; + if ((dup = ao2_find(mohclasses, class, OBJ_POINTER)) || (dup = ao2_find(deleted_classes, class, OBJ_POINTER))) { + if (_ao2_ref_debug(dup, -1, (char *) tag, (char *) file, line, funcname) == 1) { + ast_log(LOG_WARNING, "Attempt to unref mohclass %p (%s) when only 1 ref remained, and class is still in a container! (at %s:%d (%s))\n", + class, class->name, file, line, funcname); + } else { + ao2_ref(class, -1); + } + } else { + ao2_t_ref(class, -1, (char *) tag); + } + return NULL; +} +#endif static void moh_files_release(struct ast_channel *chan, void *data) {