diff --git a/steam-runtime-tools/graphics.c b/steam-runtime-tools/graphics.c
index 20ff7481c875ceb45a0b231439f24bb7639aac82..ffd1ed3bc03a78a1aa68655d2dae33bb16077221 100644
--- a/steam-runtime-tools/graphics.c
+++ b/steam-runtime-tools/graphics.c
@@ -2388,8 +2388,12 @@ _srt_get_library_class (const gchar *library)
   class = gelf_getclass (elf);
 
 out:
-  elf_end (elf);
-  close (fd);
+  if (elf != NULL)
+    elf_end (elf);
+
+  if (fd >= 0)
+    close (fd);
+
   return class;
 }