mirror of
https://github.com/crosspoint-reader/crosspoint-reader.git
synced 2026-04-29 10:26:52 -07:00
fix: two small memory leaks (#1628)
## Summary * **What is the goal of this PR?** Fix two issues pointed out by `CodeRabbit` in #1433: 1. Free the output buffer in `readFileToMemory` on early error paths (prevents memory leaks). 2. Check `out.write()` return value in the STORED path (same as in the DEFLATED path). I can confirm both issues were real (not hallucinations). Both fixes are minimal — no behavior change on success. --- ### AI Usage Did you use AI tools to help write this code? _**< NO >**_
This commit is contained in:
@@ -400,6 +400,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
|
||||
const auto deflatedData = static_cast<uint8_t*>(malloc(deflatedDataSize));
|
||||
if (deflatedData == nullptr) {
|
||||
LOG_ERR("ZIP", "Failed to allocate memory for decompression buffer");
|
||||
free(data);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -430,6 +431,7 @@ uint8_t* ZipFile::readFileToMemory(const char* filename, size_t* size, const boo
|
||||
// Continue out of block with data set
|
||||
} else {
|
||||
LOG_ERR("ZIP", "Unsupported compression method");
|
||||
free(data);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -469,7 +471,11 @@ bool ZipFile::readFileToStream(const char* filename, Print& out, const size_t ch
|
||||
return false;
|
||||
}
|
||||
|
||||
out.write(buffer, dataRead);
|
||||
if (out.write(buffer, dataRead) != dataRead) {
|
||||
LOG_ERR("ZIP", "Failed to write all output bytes to stream");
|
||||
free(buffer);
|
||||
return false;
|
||||
}
|
||||
remaining -= dataRead;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user