deallocate extension contexts on connection close

Signed-off-by: Andy Green <andy@warmcat.com>
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index 39c537f..dded30e 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -204,7 +204,20 @@
 		wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
 						      wsi->user_space, NULL, 0);
 
-	/* free up his allocations */
+	/* deallocate any active extension contexts */
+
+	for (n = 0; n < wsi->count_active_extensions; n++) {
+		if (!wsi->active_extensions[n]->callback)
+			continue;
+
+		wsi->active_extensions[n]->callback(context, wsi,
+			LWS_EXT_CALLBACK_DESTROY,
+			wsi->active_extensions_user[n], NULL, 0);
+
+		free(wsi->active_extensions_user[n]);
+	}
+
+	/* free up his parsing allocations */
 
 	for (n = 0; n < WSI_TOKEN_COUNT; n++)
 		if (wsi->utf8_token[n].token)