--- a/src/compiler/glsl/test_optpass.cpp	2018-11-02 15:24:00.031760843 +0100
+++ b/src/compiler/glsl/test_optpass.cpp	2018-11-02 15:26:42.353776478 +0100
@@ -166,6 +166,7 @@ int test_optpass(int argc, char **argv)
    int loop = 0;
    int shader_type = GL_VERTEX_SHADER;
    int quiet = 0;
+   int error;
 
    const struct option optpass_opts[] = {
       { "input-ir", no_argument, &input_format_ir, 1 },
@@ -264,9 +265,11 @@ int test_optpass(int argc, char **argv)
       printf("--\n");
    }
 
+   error = state->error;
+
    ralloc_free(state);
    ralloc_free(shader);
 
-   return state->error;
+   return error;
 }