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>
This commit is contained in:
@@ -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 {
|
||||
|
||||
مرجع در شماره جدید
Block a user