rocr: Add proper file descriptor cleanup

Ensure file descriptor 'in' is properly closed in error cases
when calling _lseek() during readFrom() operations.
Fix potential resource leak when errors occur during file operations.

Signed-off-by: Alysa Liu <Alysa.Liu@amd.com>


[ROCm/ROCR-Runtime commit: 167602edfb]
이 커밋은 다음에 포함됨:
Alysa Liu
2025-06-02 09:56:53 -04:00
커밋한 사람 Liu, Alysa
부모 1da312af87
커밋 d1c3b7262d
+12 -3
파일 보기
@@ -213,10 +213,19 @@ namespace elf {
#else // _WIN32
int in = _open(filename.c_str(), O_RDONLY);
if (in < 0) { return perror("open failed"); }
if (_lseek(in, 0L, SEEK_END) < 0) { return perror("lseek failed"); }
if (_lseek(in, 0L, SEEK_END) < 0) {
_close(in);
return perror("lseek failed");
}
off_t size;
if ((size = _lseek(in, 0L, SEEK_CUR)) < 0) { return perror("lseek(2) failed"); }
if (_lseek(in, 0L, SEEK_SET) < 0) { return perror("lseek(3) failed"); }
if ((size = _lseek(in, 0L, SEEK_CUR)) < 0) {
_close(in);
return perror("lseek(2) failed");
}
if (_lseek(in, 0L, SEEK_SET) < 0) {
_close(in);
return perror("lseek(3) failed");
}
if (_lseek(d, 0L, SEEK_SET) < 0) { return perror("lseek(3) failed"); }
ssize_t written;
do {