diff --git a/test/modules/keystore/test.c b/test/modules/keystore/test.c
index 45ef74f09bf3c76959fd31e2881e5a60119e5b73..4a7aea217146d486b56ebc501e89aeb428093995 100644
--- a/test/modules/keystore/test.c
+++ b/test/modules/keystore/test.c
@@ -85,7 +85,8 @@ ks_find(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX],
             assert(strcmp(psz_value1, psz_value2) == 0);
         }
     }
-    vlc_keystore_release_entries(p_entries, i_entries);
+    if (i_entries > 0)
+        vlc_keystore_release_entries(p_entries, i_entries);
     return i_entries;
 }