checkpoint: close rootfs tar stream after use

chrootarchive.Tar returns an io.ReadCloser backed by a pipe to the
tar-producing process.  CRCreateRootFsDiffTar copies from the stream but
never closes it.

On the successful path the stream is read to EOF, so the producer normally
exits.  On early errors, such as failing to create the destination file or
failing while copying to it, the producer can be left without a consumer.

Close the tar stream after it is created so error paths release the pipe and
allow the producer to exit.

Signed-off-by: Mikhail Dmitrichenko <m.dmitrichenko00@bk.ru>
This commit is contained in:
Mikhail Dmitrichenko 2026-06-24 12:32:15 +03:00
parent 1479c7d6b6
commit feff567126

View file

@ -166,6 +166,7 @@ func CRCreateRootFsDiffTar(changes *[]archive.Change, mountPoint, destination st
if err != nil {
return includeFiles, fmt.Errorf("exporting root file-system diff to %q: %w", rootfsDiffPath, err)
}
defer rootfsTar.Close()
rootfsDiffFile, err := os.Create(rootfsDiffPath)
if err != nil {
return includeFiles, fmt.Errorf("creating root file-system diff file %q: %w", rootfsDiffPath, err)