The call to 'fclose' immediately follows a conditional and is indented in such a way as to lead the reader to believe it is within the scope of the conditional. The conditional however is immediately followed by a ';' on the same line which makes it a no-op and causes the call to 'fclose' to happen regardless of the result of the test. Removing this ';' will get you the intended behavior.
Apologies for not sending a patch but I'm still barred from doing so on account of the CCLA.
The indentation in this block of code is misleading: https://github.com/Microsoft/ms-tpm-20-ref/blob/master/TPMCmd/Platform/src/NVMem.c#L208
The call to 'fclose' immediately follows a conditional and is indented in such a way as to lead the reader to believe it is within the scope of the conditional. The conditional however is immediately followed by a ';' on the same line which makes it a no-op and causes the call to 'fclose' to happen regardless of the result of the test. Removing this ';' will get you the intended behavior.
Apologies for not sending a patch but I'm still barred from doing so on account of the CCLA.