]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Use "goto" for error handling in io_open_dest_real()
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 27 Dec 2024 07:15:50 +0000 (09:15 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 5 Jan 2025 18:16:01 +0000 (20:16 +0200)
src/xz/file_io.c

index 9c4d6ac8e3552bae531d81ac5ed7b4ad7e0fe6c6..66458e972302c7a63a1b3ece03bbaeed6c506817 100644 (file)
@@ -828,8 +828,7 @@ io_open_dest_real(file_pair *pair)
                                                "a DOS special file",
                                                tuklib_mask_nonprint(
                                                        pair->dest_name));
-                               free(pair->dest_name);
-                               return true;
+                               goto error;
                        }
 
                        // Check that we aren't overwriting the source file.
@@ -839,8 +838,7 @@ io_open_dest_real(file_pair *pair)
                                                "as the input file",
                                                tuklib_mask_nonprint(
                                                        pair->dest_name));
-                               free(pair->dest_name);
-                               return true;
+                               goto error;
                        }
                }
 #endif
@@ -850,8 +848,7 @@ io_open_dest_real(file_pair *pair)
                        message_error(_("%s: Cannot remove: %s"),
                                        tuklib_mask_nonprint(pair->dest_name),
                                        strerror(errno));
-                       free(pair->dest_name);
-                       return true;
+                       goto error;
                }
 
                // Open the file.
@@ -867,8 +864,7 @@ io_open_dest_real(file_pair *pair)
                        message_error(_("%s: %s"),
                                        tuklib_mask_nonprint(pair->dest_name),
                                        strerror(errno));
-                       free(pair->dest_name);
-                       return true;
+                       goto error;
                }
        }
 
@@ -901,9 +897,7 @@ io_open_dest_real(file_pair *pair)
                // dest_fd needs to be reset to -1 to keep io_close() working.
                (void)close(pair->dest_fd);
                pair->dest_fd = -1;
-
-               free(pair->dest_name);
-               return true;
+               goto error;
        }
 #elif !defined(TUKLIB_DOSLIKE)
        else if (try_sparse && opt_mode == MODE_DECOMPRESS) {
@@ -975,6 +969,10 @@ io_open_dest_real(file_pair *pair)
 #endif
 
        return false;
+
+error:
+       free(pair->dest_name);
+       return true;
 }