diff --git a/subprojects/gstreamer/gst/gstregistry.c b/subprojects/gstreamer/gst/gstregistry.c
index 8a62cca6ce..c84de1d7f6 100644
--- a/subprojects/gstreamer/gst/gstregistry.c
+++ b/subprojects/gstreamer/gst/gstregistry.c
@@ -1642,6 +1642,7 @@ priv_gst_count_directories (const char *filepath)
   if (len >= 3 && G_IS_DIR_SEPARATOR (tmp[0]) && G_IS_DIR_SEPARATOR (tmp[1])
       && !G_IS_DIR_SEPARATOR (tmp[2])) {
     GST_WARNING ("found a UNC share path, ignoring");
+    g_clear_pointer (&tmp, g_free);
     return 0;
   }
 
diff --git a/subprojects/gstreamer/libs/gst/net/gstptpclock.c b/subprojects/gstreamer/libs/gst/net/gstptpclock.c
index d1a3f0e955..daf570830a 100644
--- a/subprojects/gstreamer/libs/gst/net/gstptpclock.c
+++ b/subprojects/gstreamer/libs/gst/net/gstptpclock.c
@@ -2152,6 +2152,7 @@ count_directories (const char *filepath)
   if (len >= 3 && G_IS_DIR_SEPARATOR (tmp[0]) && G_IS_DIR_SEPARATOR (tmp[1])
       && !G_IS_DIR_SEPARATOR (tmp[2])) {
     GST_WARNING ("found a UNC share path, ignoring");
+    g_clear_pointer (&tmp, g_free);
     return 0;
   }