--- asterisk-12.2.0/channels/chan_sip.c 2014-04-21 17:02:00.000000000 -0400 +++ asterisk-12.2.0-modified/channels/chan_sip.c 2014-05-24 20:44:28.559519094 -0400 @@ -6566,8 +6566,12 @@ AST_SCHED_DEL(sched, reg->expire); AST_SCHED_DEL(sched, reg->timeout); + if ((reg->registryadded)) + { + ast_atomic_fetchadd_int(®objs, -1); + } + ast_string_field_free_memory(reg); - ast_atomic_fetchadd_int(®objs, -1); ast_free(reg); } @@ -9556,6 +9560,7 @@ registry_unref(tmp, "throw away found registry"); } else { ast_atomic_fetchadd_int(®objs, 1); + reg->registryadded = 1; ASTOBJ_CONTAINER_LINK(®l, reg); } --- asterisk-12.2.0/channels/sip/include/sip.h 2014-04-21 17:02:00.000000000 -0400 +++ asterisk-12.2.0-modified/channels/sip/include/sip.h 2014-05-24 20:37:42.557555124 -0400 @@ -1414,6 +1414,7 @@ struct ast_sockaddr us; /*!< Who the server thinks we are */ int noncecount; /*!< Nonce-count */ char lastmsg[256]; /*!< Last Message sent/received */ + unsigned short registryadded:1; /*!< If this registry object is already added to registry list */ }; struct tcptls_packet {