diff --git a/libs/gst/base/gstbasetransform.c b/libs/gst/base/gstbasetransform.c
index f317d0914f..aa3ec24cf2 100644
--- a/libs/gst/base/gstbasetransform.c
+++ b/libs/gst/base/gstbasetransform.c
@@ -472,9 +472,10 @@ gst_base_transform_transform_caps (GstBaseTransform * trans,
       temp = gst_caps_make_writable (temp);
       gst_caps_append (ret, temp);
     } else {
+      gint n = gst_caps_get_size (caps);
       /* we send caps with just one structure to the transform
        * function as this is easier for the element */
-      for (i = 0; i < gst_caps_get_size (caps); i++) {
+      for (i = 0; i < n; i++) {
         GstCaps *nth;
 
         nth = gst_caps_copy_nth (caps, i);