Commit 08baa43
committed
fix(registry): prevent file descriptor leak in WriteToTextfile
In WriteToTextfile, if an error occurs before the explicit tmp.Close()
(e.g., Gather fails or MetricFamilyToText fails), the temporary file
descriptor is never closed. The deferred os.Remove(tmp.Name()) does not
close the file.
Explicitly close the file on all error paths that happen before the
final close, ensuring the descriptor is always released.
Additionally, this fixes the issue on Windows where an open file cannot
be deleted, preventing the deferred os.Remove from succeeding.
Fixes: 1d54dab ("Add WriteToTextfile test")
Found by PostgresPro.
Signed-off-by: Maksim Korotkov <m.korotkov@postgrespro.ru>1 parent d61fb3f commit 08baa43
1 file changed
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
| 644 | + | |
644 | 645 | | |
645 | 646 | | |
646 | 647 | | |
647 | 648 | | |
| 649 | + | |
648 | 650 | | |
649 | 651 | | |
650 | 652 | | |
| |||
0 commit comments