Bugfix: make sure fclose is called with a legal argument
authorKarina Litskevich <[email protected]>
Mon, 28 Aug 2023 11:53:12 +0000 (14:53 +0300)
committerKarina Litskevich <[email protected]>
Mon, 28 Aug 2023 11:54:52 +0000 (14:54 +0300)
fclose(NULL) is an UB

decode.c

index 565ef58a76ff8e77dbfb6155322a2de17a62ad70..bf281890032626f3704a73a7d4bdbf72564d4978 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -1351,8 +1351,7 @@ ReadStringFromToast(const char *buffer,
                                        toast_relation_filename);
                        result = -1;
                }
-
-               if (result == 0)
+               else
                {
                        unsigned int toast_relation_block_size = GetBlockSize(toast_rel_fp);
                        fseek(toast_rel_fp, 0, SEEK_SET);
@@ -1382,9 +1381,9 @@ ReadStringFromToast(const char *buffer,
                        }
 
                        free(toast_data);
+                       fclose(toast_rel_fp);
                }
 
-               fclose(toast_rel_fp);
                free(toast_relation_path);
        }
        /* If tag is indirect or expanded, it was stored in memory. */