diff --git a/glnx-console.h b/glnx-console.h
index 9f620cc7cc7baa079acb5315b023005c2105c59d..8fc3865672f136488e45d0581f6580d62dbc8618 100644
--- a/glnx-console.h
+++ b/glnx-console.h
@@ -45,7 +45,8 @@ guint    glnx_console_columns (void);
 static inline void
 glnx_console_ref_cleanup (GLnxConsoleRef *p)
 {
-  glnx_console_unlock (p);
+  if (p->locked)
+    glnx_console_unlock (p);
 }
 G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GLnxConsoleRef, glnx_console_ref_cleanup)