Fix CID 1393239 (Dereference null return value)

Add also some error handling if fopen fails.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
This commit is contained in:
Stefan Weil 2018-06-20 19:43:00 +02:00
parent b344dc14ad
commit 27a5908a55

View File

@ -1195,8 +1195,12 @@ bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* filename,
if (failed && retry_config != nullptr && retry_config[0] != '\0') {
// Save current config variables before switching modes.
FILE* fp = fopen(kOldVarsFile, "wb");
PrintVariables(fp);
fclose(fp);
if (fp == nullptr) {
tprintf("Error, failed to open file \"%s\"\n", kOldVarsFile);
} else {
PrintVariables(fp);
fclose(fp);
}
// Switch to alternate mode for retry.
ReadConfigFile(retry_config);
SetImage(pix);