diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 2c4b21f1f08c553d65fd748286658298942897c7..282ae994155809d7286e3a71659f76c994505829 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -1081,6 +1081,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
 		pthread_attr_init(&conf->attr);
 		pthread_attr_setdetachstate(&conf->attr, PTHREAD_CREATE_DETACHED);
 		ast_pthread_create_background(&conf->recordthread, &conf->attr, recordthread, conf);
+		pthread_attr_destroy(&conf->attr);
 	}
 
 	time(&user->jointime);
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 7d153c1b8bb688453ea506830ba1974581a7c72c..3739feb7ae0a74c3760efc9ceab61e57b9ab7707 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -631,6 +631,7 @@ static int statechange_queue(const char *dev, int state, void *ign)
 		ast_log(LOG_WARNING, "Failed to create update thread!\n");
 		free(sc);
 	}
+	pthread_attr_destroy(&attr);
 
 	return 0;
 }
diff --git a/apps/app_rpt.c b/apps/app_rpt.c
index 73a817a84498411b0093eb3948a4bf3a7fb356b2..54f313cc7432124bea93c413220b19650ea2873f 100644
--- a/apps/app_rpt.c
+++ b/apps/app_rpt.c
@@ -3188,6 +3188,7 @@ static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf,
 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 	ast_pthread_create(&myrpt->rpt_call_thread, &attr, rpt_call, (void *) myrpt);
 	pthread_attr_destroy(&attr);
+	pthread_attr_destroy(&attr);
 	return DC_COMPLETE;
 }
 
@@ -5541,6 +5542,7 @@ static void local_dtmf_helper(struct rpt *myrpt, char c)
 			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 			ast_pthread_create(&myrpt->rpt_call_thread, &attr, rpt_call, (void *)myrpt);
 			pthread_attr_destroy(&attr);
+			pthread_attr_destroy(&attr);
 			return;
 		}
 	}
@@ -6736,6 +6738,7 @@ static void *rpt_master(void *config)
 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 		ast_pthread_create(&rpt_vars[i].rpt_thread, &attr, rpt, (void *) &rpt_vars[i]);
 		pthread_attr_destroy(&attr);
+		pthread_attr_destroy(&attr);
 	}
 	usleep(500000);
 	for (;;) {
@@ -6765,6 +6768,7 @@ static void *rpt_master(void *config)
 	 			pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 				ast_pthread_create(&rpt_vars[i].rpt_thread, &attr, rpt, (void *) &rpt_vars[i]);
 				pthread_attr_destroy(&attr);
+				pthread_attr_destroy(&attr);
 				ast_log(LOG_WARNING, "rpt_thread restarted on node %s\n", rpt_vars[i].name);
 			}
 
diff --git a/channels/chan_h323.c b/channels/chan_h323.c
index 5de07ab244c9a867cdc0d94b896fdeefa13a3b53..3e16a85cc306377b9864e63dfd3432d104642787 100644
--- a/channels/chan_h323.c
+++ b/channels/chan_h323.c
@@ -2610,8 +2610,10 @@ static int restart_monitor(void)
 			monitor_thread = AST_PTHREADT_NULL;
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
+			pthread_attr_destroy(&attr);
 			return -1;
 		}
+		pthread_attr_destroy(&attr);
 	}
 	ast_mutex_unlock(&monlock);
 	return 0;
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 66f0b97b645e2d37d4aa48ee2201767a540e4538..f9a4d3f9441c6152d13257a8831d2a89afbba793 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -6163,6 +6163,8 @@ static void spawn_dp_lookup(int callno, const char *context, const char *calledn
 	if (ast_pthread_create(&newthread, &attr, dp_lookup_thread, dpr)) {
 		ast_log(LOG_WARNING, "Unable to start lookup thread!\n");
 	}
+
+	pthread_attr_destroy(&attr);
 }
 
 struct iax_dual {
@@ -6237,8 +6239,11 @@ static int iax_park(struct ast_channel *chan1, struct ast_channel *chan2)
 
 		d->chan1 = chan1m;
 		d->chan2 = chan2m;
-		if (!ast_pthread_create_background(&th, &attr, iax_park_thread, d))
+		if (!ast_pthread_create_background(&th, &attr, iax_park_thread, d)) {
+			pthread_attr_destroy(&attr);
 			return 0;
+		}
+		pthread_attr_destroy(&attr);
 		free(d);
 	}
 	return -1;
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index ce685527c1532ce3b4e1556d7f5713592a67ea85..69a0cc03f3f783b27d7a1358f7ef79859036ec51 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -3007,6 +3007,7 @@ static void handle_hd_hf(struct mgcp_subchannel *sub, char *ev)
 			/*ast_queue_control(sub->owner, AST_CONTROL_ANSWER);*/
 		}
 	}
+	pthread_attr_destroy(&attr);
 }
 
 static int handle_request(struct mgcp_subchannel *sub, struct mgcp_request *req, struct sockaddr_in *sin)
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index c1478a53c79ec734845371e11a1fd2a7e8de1e7a..a937c053a0393502af0aa937e2e0d5be9943034b 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -12841,8 +12841,10 @@ static int sip_park(struct ast_channel *chan1, struct ast_channel *chan2, struct
 			/* Could not start thread */
 			free(d);	/* We don't need it anymore. If thread is created, d will be free'd
 					   by sip_park_thread() */
+			pthread_attr_destroy(&attr);
 			return 0;
 		}
+		pthread_attr_destroy(&attr);
 	} 
 	return -1;
 }
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index c07d361a4bbe881818deec4d978a1d01461fa8f0..f6f68ea1625d2169ff7922c570e24dd87f2de7e3 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -4307,6 +4307,7 @@ static void *accept_thread(void *ignore)
 	if (skinnydebug)
 		ast_verbose("killing accept thread\n");
 	close(as);
+	pthread_attr_destroy(&attr);
 	return 0;
 }
 
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index 8c56208322b8b0f7df8868f0eef6a9919d5b9dfb..99faf8c26467ed4d4e59c28b63d97267b4e15a7a 100644
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -3837,9 +3837,6 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
 	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);
 	mysig = p->sig;
 	if (p->outsigmod > -1)
@@ -4438,6 +4435,8 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
 						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)) {
@@ -4455,7 +4454,8 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
 									!ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
 							}
 							p->subs[SUB_THREEWAY].needhold = 1;
-						}		
+						}
+						pthread_attr_destroy(&attr);
 					}
 				} else {
 					/* Already have a 3 way call */
@@ -7049,6 +7049,7 @@ static int handle_init_event(struct zt_pvt *i, int event)
 				"interface %d\n", i->channel);
 		}
 	}
+	pthread_attr_destroy(&attr);
 	return 0;
 }
 
@@ -7273,10 +7274,12 @@ static int restart_monitor(void)
 		if (ast_pthread_create_background(&monitor_thread, &attr, do_monitor, NULL) < 0) {
 			ast_mutex_unlock(&monlock);
 			ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
+			pthread_attr_destroy(&attr);
 			return -1;
 		}
 	}
 	ast_mutex_unlock(&monlock);
+	pthread_attr_destroy(&attr);
 	return 0;
 }
 
@@ -9180,9 +9183,6 @@ static void *pri_dchannel(void *vpri)
 	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 */
@@ -9674,6 +9674,8 @@ static void *pri_dchannel(void *vpri)
 								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",
@@ -9689,6 +9691,7 @@ static void *pri_dchannel(void *vpri)
 									pri->pvts[chanpos]->call = NULL;
 								}
 							}
+							pthread_attr_destroy(&attr);
 						} else  {
 							ast_mutex_unlock(&pri->lock);
 							/* Release PRI lock while we create the channel */
diff --git a/main/cdr.c b/main/cdr.c
index e8eebe10fc29d0981db909a3b1f9b6b4b0ede42d..33f326b86fac72c86004aef0c0e00777dd2f6657 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -861,6 +861,7 @@ void ast_cdr_submit_batch(int shutdown)
 			if (option_debug)
 				ast_log(LOG_DEBUG, "CDR multi-threaded batch processing begins now\n");
 		}
+		pthread_attr_destroy(&attr);
 	}
 }
 
diff --git a/main/http.c b/main/http.c
index 30c4e930ef04e529362e81f9954bfc8c9023a416..3d0b7f703f477a2ad6e1e0eb3b0f36baf56d2127 100644
--- a/main/http.c
+++ b/main/http.c
@@ -684,6 +684,8 @@ void *server_root(void *data)
 			close(ser->fd);
 			free(ser);
 		}
+
+		pthread_attr_destroy(&attr);
 	}
 	return NULL;
 }
diff --git a/main/manager.c b/main/manager.c
index b84cd9ba560c366cde4dad18e0128f3a39629764..4a63b67647934e730cacc71ab81406824ccce20b 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1841,6 +1841,7 @@ static int action_originate(struct mansession *s, const struct message *m)
 			} 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, account, NULL);
diff --git a/main/pbx.c b/main/pbx.c
index a3a0ebe37cd049b77c757dca4baf80251dcf22c0..f60b2b2bd9893d47f379cb30a8b0d3b4bab7b5aa 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -2506,8 +2506,10 @@ enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
 	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");
+		pthread_attr_destroy(&attr);
 		return AST_PBX_FAILED;
 	}
+	pthread_attr_destroy(&attr);
 
 	return AST_PBX_SUCCESS;
 }
@@ -5015,8 +5017,10 @@ int ast_pbx_outgoing_exten(const char *type, int format, void *data, int timeout
 			}
 			ast_hangup(chan);
 			res = -1;
+			pthread_attr_destroy(&attr);
 			goto outgoing_exten_cleanup;
 		}
+		pthread_attr_destroy(&attr);
 		res = 0;
 	}
 outgoing_exten_cleanup:
@@ -5118,6 +5122,7 @@ int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout,
 							if (locked_channel)
 								*locked_channel = chan;
 						}
+						pthread_attr_destroy(&attr);
 					}
 				}
 			} else {
@@ -5176,11 +5181,13 @@ int ast_pbx_outgoing_app(const char *type, int format, void *data, int timeout,
 				ast_channel_unlock(chan);
 			ast_hangup(chan);
 			res = -1;
+			pthread_attr_destroy(&attr);
 			goto outgoing_app_cleanup;
 		} else {
 			if (locked_channel)
 				*locked_channel = chan;
 		}
+		pthread_attr_destroy(&attr);
 		res = 0;
 	}
 outgoing_app_cleanup:
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index d2fcfb45468fb721a2b43c16e7fdbbf9c929a771..cd7e969370f18b8b986c26b2fdb2695380023b08 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -790,8 +790,10 @@ static int dundi_answer_entity(struct dundi_transaction *trans, struct dundi_ies
 			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);
+			pthread_attr_destroy(&attr);
 			return -1;
 		}
+		pthread_attr_destroy(&attr);
 	} else {
 		ast_log(LOG_WARNING, "Out of memory!\n");
 		memset(&ied, 0, sizeof(ied));
@@ -1019,8 +1021,10 @@ static int dundi_prop_precache(struct dundi_transaction *trans, struct dundi_ies
 			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);
+			pthread_attr_destroy(&attr);
 			return -1;
 		}
+		pthread_attr_destroy(&attr);
 	} else {
 		ast_log(LOG_WARNING, "Out of memory!\n");
 		memset(&ied, 0, sizeof(ied));
@@ -1106,8 +1110,10 @@ static int dundi_answer_query(struct dundi_transaction *trans, struct dundi_ies
 			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);
+			pthread_attr_destroy(&attr);
 			return -1;
 		}
+		pthread_attr_destroy(&attr);
 	} else {
 		ast_log(LOG_WARNING, "Out of memory!\n");
 		memset(&ied, 0, sizeof(ied));
diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c
index 6325f92ebf169dd7e22690f56761d5f3a7bdd281..e84ebaaf551051bfd21fa4c7fb77276b25f47449 100644
--- a/pbx/pbx_spool.c
+++ b/pbx/pbx_spool.c
@@ -367,6 +367,7 @@ static void launch_service(struct outgoing *o)
 		ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
 		free_outgoing(o);
 	}
+	pthread_attr_destroy(&attr);
 }
 
 static int scan_service(char *fn, time_t now, time_t atime)
@@ -499,6 +500,7 @@ static int load_module(void)
 		ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
 		return -1;
 	}
+	pthread_attr_destroy(&attr);
 	return 0;
 }