diff --git a/res/res_pjsip/config_system.c b/res/res_pjsip/config_system.c
index 8c4c548fa5e14edbb0002abdb80a8374c6269a0d..f88b96b895d3fd937776f1b259d6f4d916d917c4 100644
--- a/res/res_pjsip/config_system.c
+++ b/res/res_pjsip/config_system.c
@@ -201,6 +201,7 @@ static int system_create_resolver_and_set_nameservers(void *data)
 		status = pjsip_endpt_create_resolver(ast_sip_get_pjsip_endpoint(), &resolver);
 		if (status != PJ_SUCCESS) {
 			ast_log(LOG_ERROR, "Could not create DNS resolver(%d), resorting to system resolution\n", status);
+			ao2_ref(discovered_nameservers, -1);
 			return 0;
 		}
 	}
@@ -241,4 +242,4 @@ static int system_create_resolver_and_set_nameservers(void *data)
 void ast_sip_initialize_dns(void)
 {
 	ast_sip_push_task_synchronous(NULL, system_create_resolver_and_set_nameservers, NULL);
-}
\ No newline at end of file
+}