Index: utils.c =================================================================== --- utils.c (revision 7522) +++ utils.c (working copy) @@ -487,9 +487,11 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize) { pthread_attr_t lattr; + int init = 0, res; if (!attr) { pthread_attr_init(&lattr); attr = &lattr; + init = 1; } #ifdef __linux__ /* On Linux, pthread_attr_init() defaults to PTHREAD_EXPLICIT_SCHED, @@ -509,7 +511,10 @@ errno = pthread_attr_setstacksize(attr, stacksize); if (errno) ast_log(LOG_WARNING, "pthread_attr_setstacksize returned non-zero: %s\n", strerror(errno)); - return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */ + res = pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */ + if (init) + pthread_attr_destroy(&lattr); + return res; } int ast_wait_for_input(int fd, int ms) Index: pbx/pbx_spool.c =================================================================== --- pbx/pbx_spool.c (revision 7522) +++ pbx/pbx_spool.c (working copy) @@ -55,6 +55,7 @@ static char *tdesc = "Outgoing Spool Support"; static char qdir[255]; +static pthread_attr_t attr; struct outgoing { char fn[256]; @@ -288,9 +289,6 @@ static void launch_service(struct outgoing *o) { pthread_t t; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ast_pthread_create(&t,&attr,attempt_thread, o) == -1) { ast_log(LOG_WARNING, "Unable to create thread :(\n"); free_outgoing(o); @@ -412,7 +410,6 @@ int load_module(void) { pthread_t thread; - pthread_attr_t attr; snprintf(qdir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing"); if (mkdir(qdir, 0700) && (errno != EEXIST)) { ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool disabled\n", qdir); Index: pbx/pbx_dundi.c =================================================================== --- pbx/pbx_dundi.c (revision 7522) +++ pbx/pbx_dundi.c (working copy) @@ -756,7 +756,7 @@ { struct dundi_query_state *st; int totallen; - int x; + int x, res = 0; int skipfirst=0; struct dundi_ie_data ied; char eid_str[20]; @@ -799,16 +799,17 @@ memset(&ied, 0, sizeof(ied)); dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads"); dundi_send(trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied); - return -1; + res = -1; } + pthread_attr_destroy(&attr); } else { ast_log(LOG_WARNING, "Out of memory!\n"); memset(&ied, 0, sizeof(ied)); dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of memory"); dundi_send(trans, DUNDI_COMMAND_EIDRESPONSE, 0, 1, &ied); - return -1; + res = -1; } - return 0; + return res; } static int cache_save_hint(dundi_eid *eidpeer, struct dundi_request *req, struct dundi_hint *hint, int expiration) @@ -891,7 +892,7 @@ { struct dundi_query_state *st; int totallen; - int x,z; + int x,z, res = 0; struct dundi_ie_data ied; char *s; struct dundi_result dr2[MAX_RESULTS]; @@ -1030,23 +1031,24 @@ memset(&ied, 0, sizeof(ied)); dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads"); dundi_send(trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied); - return -1; + res = -1; } + pthread_attr_destroy(&attr); } else { ast_log(LOG_WARNING, "Out of memory!\n"); memset(&ied, 0, sizeof(ied)); dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of memory"); dundi_send(trans, DUNDI_COMMAND_PRECACHERP, 0, 1, &ied); - return -1; + res = -1; } - return 0; + return res; } static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies *ies, char *ccontext) { struct dundi_query_state *st; int totallen; - int x; + int x, res = 0; struct dundi_ie_data ied; char *s; struct dundi_mapping *cur; @@ -1122,16 +1124,17 @@ memset(&ied, 0, sizeof(ied)); dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of threads"); dundi_send(trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied); - return -1; + res = -1; } + pthread_attr_destroy(&attr); } else { ast_log(LOG_WARNING, "Out of memory!\n"); memset(&ied, 0, sizeof(ied)); dundi_ie_append_cause(&ied, DUNDI_IE_CAUSE, DUNDI_CAUSE_GENERAL, "Out of memory"); dundi_send(trans, DUNDI_COMMAND_DPRESPONSE, 0, 1, &ied); - return -1; + res = -1; } - return 0; + return res; } static int cache_lookup_internal(time_t now, struct dundi_request *req, char *key, char *eid_str_full, int *lowexpiration) Index: cdr.c =================================================================== --- cdr.c (revision 7522) +++ cdr.c (working copy) @@ -952,6 +952,7 @@ if (option_debug) ast_log(LOG_DEBUG, "CDR multi-threaded batch processing begins now\n"); } + pthread_attr_destroy(&attr); } } @@ -1207,6 +1208,7 @@ ast_register_atexit(ast_cdr_engine_term); res = 0; } + pthread_attr_destroy(&attr); /* if this reload disabled the CDR and/or batch mode and there is a background thread, kill it */ } else if (((!enabled && was_enabled) || (!batchmode && was_batchmode)) && (cdr_thread != AST_PTHREADT_NULL)) { Index: channels/chan_h323.c =================================================================== --- channels/chan_h323.c (revision 7522) +++ channels/chan_h323.c (working copy) @@ -98,6 +98,8 @@ /* global debug flag */ int h323debug; +static pthread_attr_t attr; + /** Variables required by Asterisk */ static const char type[] = "H323"; static const char desc[] = "The NuFone Network's Open H.323 Channel Driver"; @@ -1623,7 +1625,6 @@ static int restart_monitor(void) { - pthread_attr_t attr; /* If we're supposed to be stopped -- stay stopped */ if (monitor_thread == AST_PTHREADT_STOP) { return 0; @@ -1641,15 +1642,12 @@ /* Wake up the thread */ pthread_kill(monitor_thread, SIGURG); } else { - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - /* Start a new monitor */ - if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) { - ast_mutex_unlock(&monlock); - ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); - return -1; - } - + /* Start a new monitor */ + if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) { + ast_mutex_unlock(&monlock); + ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); + return -1; + } } ast_mutex_unlock(&monlock); return 0; @@ -2319,6 +2317,9 @@ ast_mutex_init(&userl.lock); ast_mutex_init(&peerl.lock); ast_mutex_init(&aliasl.lock); + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + sched = sched_context_create(); if (!sched) { ast_log(LOG_WARNING, "Unable to create schedule context\n"); @@ -2397,7 +2398,7 @@ ast_cli_unregister(&cli_h323_reload); ast_rtp_proto_unregister(&oh323_rtp); ast_channel_unregister(&oh323_tech); - + if (!ast_mutex_lock(&iflock)) { /* hangup all interfaces if they have an owner */ p = iflist; @@ -2449,6 +2450,7 @@ delete_users(); delete_aliases(); prune_peers(); + pthread_attr_destroy(&attr); ast_mutex_destroy(&aliasl.lock); ast_mutex_destroy(&userl.lock); ast_mutex_destroy(&peerl.lock); Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (revision 7522) +++ channels/chan_zap.c (working copy) @@ -3495,9 +3495,6 @@ pthread_attr_t attr; struct ast_channel *chan; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - index = zt_get_index(ast, p, 0); p->subs[index].f.frametype = AST_FRAME_NULL; p->subs[index].f.datalen = 0; @@ -4026,6 +4023,10 @@ if (res) ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel); p->owner = chan; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (!chan) { ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", p->channel); } else if (ast_pthread_create(&threadid, &attr, ss_thread, chan)) { @@ -4039,7 +4040,8 @@ /* Start music on hold if appropriate */ if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) ast_moh_start(ast_bridged_channel(p->subs[SUB_THREEWAY].owner), NULL); - } + } + pthread_attr_destroy(&attr); } } else { /* Already have a 3 way call */ @@ -6386,6 +6388,7 @@ "interface %d\n", i->channel); } } + pthread_attr_destroy(&attr); return 0; } @@ -6625,6 +6628,7 @@ static int restart_monitor(void) { + int res = 0; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); @@ -6652,16 +6656,16 @@ } else { /* Start a new monitor */ if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) { - ast_mutex_unlock(&monlock); ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); - return -1; + res = -1; } } #if 0 printf("Created thread %ld detached in restart monitor\n", monitor_thread); #endif ast_mutex_unlock(&monlock); - return 0; + pthread_attr_destroy(&attr); + return res; } #ifdef ZAPATA_PRI @@ -8015,9 +8019,6 @@ char plancallingani[256]; char calledtonstr[10]; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - gettimeofday(&lastidle, NULL); if (!ast_strlen_zero(pri->idledial) && !ast_strlen_zero(pri->idleext)) { /* Need to do idle dialing, check to be sure though */ @@ -8506,6 +8507,10 @@ pbx_builtin_setvar_helper(c, "PRIREDIRECTREASON", redirectingreason2str(e->ring.redirectingreason)); ast_mutex_lock(&pri->lock); + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (c && !ast_pthread_create(&threadid, &attr, ss_thread, c)) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Accepting overlap call from '%s' to '%s' on channel %d/%d, span %d\n", @@ -8521,6 +8526,7 @@ pri->pvts[chanpos]->call = NULL; } } + pthread_attr_destroy(&attr); } else { ast_mutex_unlock(&pri->lock); /* Release PRI lock while we create the channel */ Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 7522) +++ channels/chan_sip.c (working copy) @@ -118,6 +118,8 @@ static int max_expiry = DEFAULT_MAX_EXPIRY; static int default_expiry = DEFAULT_DEFAULT_EXPIRY; +static pthread_attr_t attr; + #ifndef MAX #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif @@ -11316,7 +11318,6 @@ /*! \brief restart_monitor: Start the channel monitor thread ---*/ static int restart_monitor(void) { - pthread_attr_t attr; /* If we're supposed to be stopped -- stay stopped */ if (monitor_thread == AST_PTHREADT_STOP) return 0; @@ -11333,8 +11334,6 @@ /* Wake up the thread */ pthread_kill(monitor_thread, SIGURG); } else { - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* Start a new monitor */ if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) { ast_mutex_unlock(&monlock); @@ -13070,6 +13069,9 @@ ASTOBJ_CONTAINER_INIT(&peerl); /* Peer object list */ ASTOBJ_CONTAINER_INIT(®l); /* Registry object list */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + sched = sched_context_create(); if (!sched) { ast_log(LOG_WARNING, "Unable to create schedule context\n"); @@ -13194,6 +13196,8 @@ return -1; } + pthread_attr_destroy(&attr); + /* Free memory for local network address mask */ ast_free_ha(localaddr); Index: channels/chan_skinny.c =================================================================== --- channels/chan_skinny.c (revision 7522) +++ channels/chan_skinny.c (working copy) @@ -2951,11 +2951,7 @@ struct skinnysession *s; struct protoent *p; int arg = 1; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - for (;;) { sinlen = sizeof(sin); as = accept(skinnysock, (struct sockaddr *)&sin, &sinlen); Index: channels/chan_mgcp.c =================================================================== --- channels/chan_mgcp.c (revision 7522) +++ channels/chan_mgcp.c (working copy) @@ -133,6 +133,8 @@ #define INADDR_NONE (in_addr_t)(-1) #endif +static pthread_attr_t attr; + static const char desc[] = "Media Gateway Control Protocol (MGCP)"; static const char type[] = "MGCP"; static const char tdesc[] = "Media Gateway Control Protocol (MGCP)"; @@ -2902,9 +2904,6 @@ struct mgcp_endpoint *p = sub->parent; struct ast_channel *c; pthread_t t; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* Off hook / answer */ if (sub->outgoing) { @@ -3469,9 +3468,7 @@ static int restart_monitor(void) { - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + int res = 0; /* If we're supposed to be stopped -- stay stopped */ if (monitor_thread == AST_PTHREADT_STOP) @@ -3493,11 +3490,11 @@ if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) { ast_mutex_unlock(&monlock); ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); - return -1; + res = -1; } } ast_mutex_unlock(&monlock); - return 0; + return res; } static struct ast_channel *mgcp_request(const char *type, int format, void *data, int *cause) Index: manager.c =================================================================== --- manager.c (revision 7522) +++ manager.c (working copy) @@ -1081,6 +1081,7 @@ } else { res = 0; } + pthread_attr_destroy(&attr); } } else if (!ast_strlen_zero(app)) { res = ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, data, to, app, appdata, &reason, 1, l, n, vars, NULL); Index: apps/app_rpt.c =================================================================== --- apps/app_rpt.c (revision 7522) +++ apps/app_rpt.c (working copy) @@ -240,6 +240,7 @@ static int debug = 0; /* Set this >0 for extra debug output */ static int nrpts = 0; +static pthread_attr_t attr; char *discstr = "!!DISCONNECT!!"; static char *remote_rig_ft897="ft897"; @@ -1491,9 +1492,8 @@ static void rpt_telemetry(struct rpt *myrpt,int mode, void *data) { -struct rpt_tele *tele; -struct rpt_link *mylink = (struct rpt_link *) data; -pthread_attr_t attr; + struct rpt_tele *tele; + struct rpt_link *mylink = (struct rpt_link *) data; tele = malloc(sizeof(struct rpt_tele)); if (!tele) @@ -1519,8 +1519,6 @@ } insque((struct qelem *)tele,(struct qelem *)myrpt->tele.next); ast_mutex_unlock(&myrpt->lock); - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&tele->threadid,&attr,rpt_tele_thread,(void *) tele); return; } @@ -2127,9 +2125,6 @@ static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink) { - pthread_attr_t attr; - - if (!myrpt->enable) return DC_ERROR; @@ -2151,8 +2146,6 @@ myrpt->cidx = 0; myrpt->exten[myrpt->cidx] = 0; ast_mutex_unlock(&myrpt->lock); - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *) myrpt); return DC_COMPLETE; } @@ -4534,7 +4527,6 @@ time_t dtmf_time,t; struct rpt_link *l,*m; struct rpt_tele *telem; -pthread_attr_t attr; char tmpstr[300]; char cmd[MAXDTMF+1] = ""; @@ -5237,8 +5229,6 @@ myrpt->cidx = 0; myrpt->exten[myrpt->cidx] = 0; ast_mutex_unlock(&myrpt->lock); - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *)myrpt); continue; } @@ -5609,7 +5599,6 @@ char *this,*val; struct ast_variable *vp; int i,j,n,longestnode; -pthread_attr_t attr; /* start with blank config */ memset(&rpt_vars,0,sizeof(rpt_vars)); @@ -5779,8 +5768,6 @@ ast_config_destroy(cfg); pthread_exit(NULL); } - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]); } usleep(500000); @@ -5814,8 +5801,6 @@ rpt_vars[i].threadrestarts = 0; rpt_vars[i].lastthreadrestarttime = time(NULL); - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]); ast_log(LOG_WARNING, "rpt_thread restarted on node %s\n", rpt_vars[i].name); } @@ -6528,11 +6513,16 @@ /* Unregister cli extensions */ ast_cli_unregister(&cli_debug); + pthread_attr_destroy(&attr); + return i; } int load_module(void) { + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + ast_pthread_create(&rpt_master_thread,NULL,rpt_master,NULL); /* Register cli extensions */ Index: apps/app_page.c =================================================================== --- apps/app_page.c (revision 7522) +++ apps/app_page.c (working copy) @@ -62,6 +62,8 @@ LOCAL_USER_DECL; +static pthread_attr_t attr; + enum { PAGE_DUPLEX = (1 << 0), PAGE_QUIET = (1 << 1), @@ -97,7 +99,6 @@ struct ast_variable *lastvar = NULL; struct ast_var_t *varptr; pthread_t t; - pthread_attr_t attr; cd = malloc(sizeof(struct calloutdata)); if (cd) { memset(cd, 0, sizeof(struct calloutdata)); @@ -129,8 +130,6 @@ } } - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ast_pthread_create(&t, &attr, page_thread, cd)) { ast_log(LOG_WARNING, "Unable to create paging thread: %s\n", strerror(errno)); free(cd); @@ -206,11 +205,14 @@ STANDARD_HANGUP_LOCALUSERS; + pthread_attr_destroy(&attr); return res; } int load_module(void) { + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); return ast_register_application(app_page, page_exec, page_synopsis, page_descrip); } Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 7522) +++ apps/app_queue.c (working copy) @@ -230,6 +230,8 @@ /*! \brief queues.conf per-queue weight option */ static int use_weight = 0; +static pthread_attr_t attr; + enum queue_result { QUEUE_UNKNOWN = 0, QUEUE_TIMEOUT = 1, @@ -507,14 +509,11 @@ the event */ struct statechange *sc; pthread_t t; - pthread_attr_t attr; sc = malloc(sizeof(struct statechange) + strlen(dev) + 1); if (sc) { sc->state = state; strcpy(sc->dev, dev); - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ast_pthread_create(&t, &attr, changethread, sc)) { ast_log(LOG_WARNING, "Failed to create update thread!\n"); free(sc); @@ -3786,13 +3785,18 @@ STANDARD_HANGUP_LOCALUSERS; + pthread_attr_destroy(&attr); + return res; } int load_module(void) { int res; - + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + res = ast_register_application(app, queue_exec, synopsis, descrip); res |= ast_cli_register(&cli_show_queue); res |= ast_cli_register(&cli_show_queues); Index: asterisk.c =================================================================== --- asterisk.c (revision 7522) +++ asterisk.c (working copy) @@ -619,6 +619,7 @@ } } } + pthread_attr_destroy(&attr); return NULL; } Index: devicestate.c =================================================================== --- devicestate.c (revision 7522) +++ devicestate.c (working copy) @@ -272,14 +272,16 @@ int ast_device_state_engine_init(void) { pthread_attr_t attr; + int res = 0; ast_cond_init(&change_pending, NULL); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ast_pthread_create(&change_thread, &attr, do_devstate_changes, NULL) < 0) { ast_log(LOG_ERROR, "Unable to start device state change thread.\n"); - return -1; + res = -1; } + pthread_attr_destroy(&attr); - return 0; + return res; } Index: pbx.c =================================================================== --- pbx.c (revision 7522) +++ pbx.c (working copy) @@ -2516,6 +2516,7 @@ { pthread_t t; pthread_attr_t attr; + enum ast_pbx_result res = AST_PBX_SUCCESS; if (!c) { ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n"); @@ -2530,10 +2531,11 @@ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (ast_pthread_create(&t, &attr, pbx_thread, c)) { ast_log(LOG_WARNING, "Failed to create new channel thread\n"); - return AST_PBX_FAILED; + res = AST_PBX_FAILED; } + pthread_attr_destroy(&attr); - return AST_PBX_SUCCESS; + return res; } enum ast_pbx_result ast_pbx_run(struct ast_channel *c) @@ -5091,9 +5093,10 @@ *channel = NULL; ast_hangup(chan); res = -1; - goto outgoing_exten_cleanup; + } else { + res = 0; } - res = 0; + pthread_attr_destroy(&attr); } outgoing_exten_cleanup: ast_variables_destroy(vars); @@ -5191,6 +5194,7 @@ if (locked_channel) *locked_channel = chan; } + pthread_attr_destroy(&attr); } } else { ast_log(LOG_ERROR, "Out of memory :(\n"); @@ -5251,12 +5255,12 @@ ast_mutex_unlock(&chan->lock); ast_hangup(chan); res = -1; - goto outgoing_app_cleanup; } else { if (locked_channel) *locked_channel = chan; + res = 0; } - res = 0; + pthread_attr_destroy(&attr); } outgoing_app_cleanup: ast_variables_destroy(vars); Index: dnsmgr.c =================================================================== --- dnsmgr.c (revision 7522) +++ dnsmgr.c (working copy) @@ -353,6 +353,7 @@ refresh_sched = ast_sched_add_variable(sched, 100, refresh_list, &master_refresh_info, 1); res = 0; } + pthread_attr_destroy(&attr); } /* if this reload disabled the manager and there is a background thread, kill it */ Index: res/res_features.c =================================================================== --- res/res_features.c (revision 7522) +++ res/res_features.c (working copy) @@ -72,6 +72,8 @@ #define AST_MAX_WATCHERS 256 +static pthread_attr_t attr; + static char *parkedcall = "ParkedCall"; /* No more than 45 seconds parked before you do something with them */ @@ -243,13 +245,9 @@ static void ast_bridge_call_thread_launch(void *data) { pthread_t thread; - pthread_attr_t attr; struct sched_param sched; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); ast_pthread_create(&thread, &attr,ast_bridge_call_thread, data); - pthread_attr_destroy(&attr); memset(&sched, 0, sizeof(sched)); pthread_setschedparam(thread, SCHED_RR, &sched); } @@ -2127,7 +2125,10 @@ int load_module(void) { int res; - + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + AST_LIST_HEAD_INIT(&feature_list); memset(parking_ext, 0, sizeof(parking_ext)); memset(parking_con, 0, sizeof(parking_con)); @@ -2151,6 +2152,8 @@ { STANDARD_HANGUP_LOCALUSERS; + pthread_attr_destroy(&attr); + ast_manager_unregister("ParkedCalls"); ast_cli_unregister(&showfeatures); ast_cli_unregister(&showparked);