diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index 573d2dd387..70a1b5526f 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -5686,7 +5686,10 @@ char *sofia_glue_get_path_from_contact(char *buf)
 		}
 	}
 
-	if (!path) return NULL;
+	if (!path) {
+		free(contact);
+		return NULL;
+	}
 
 	if ((e = strrchr(path, ';'))) {
 		*e = '\0';