diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index 1e130e77152574d2b10f4c5676491ed3fbf027a4..04db2dda95a9829662fae8e2efbd58973d9fd4ea 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -440,6 +440,10 @@ static void xmpp_client_destructor(void *obj)
 
 	ast_xmpp_client_disconnect(client);
 
+	if (client->filter) {
+		iks_filter_delete(client->filter);
+	}
+
 	if (client->stack) {
 		iks_stack_delete(client->stack);
 	}
@@ -3408,12 +3412,6 @@ int ast_xmpp_client_disconnect(struct ast_xmpp_client *client)
 		iks_disconnect(client->parser);
 	}
 
-	/* Disconnecting the parser and going back to a disconnected state means any hooks should no longer be present */
-	if (client->filter) {
-		iks_filter_delete(client->filter);
-		client->filter = NULL;
-	}
-
 	client->state = XMPP_STATE_DISCONNECTED;
 
 	return 0;