Repository navigation
bugfix(mapcache): Close files and free buffers when a map preview copy or a map load fails - #3485
tintinhamans wants to merge 1 commit into
Conversation
3b29348 to
5a61292
Compare
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 12 minutes. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Walkthrough
ChangesMap failure-path cleanup
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to Map parsing and preview-copy failure paths now clean up the reported state and resources. The remaining unchanged exception path adds no new merge risk in this PR. Pre-merge checks ·
|
|
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7e468575-3b0d-4752-acb2-eca8a9b6c528
📒 Files selected for processing (1)
Core/GameEngine/Source/GameClient/MapUtil.cpp
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
5a61292 to
5a20064
Compare
| } | ||
| catch (...) | ||
| { | ||
| resetMap(); |
There was a problem hiding this comment.
🟡 Medium GameClient/MapUtil.cpp:245
A corrupt map that parses WorldInfo before failing leaves worldDict and scalar map state populated, so a later scan can attribute stale metadata such as m_nameLookupTag to another map without valid world info. resetMap() does not clear that parsed state; clear it on failure along with the other map state.
🤖 Copy this AI Prompt to have your agent fix this:
In file @Core/GameEngine/Source/GameClient/MapUtil.cpp around line 245:
A corrupt map that parses `WorldInfo` before failing leaves `worldDict` and scalar map state populated, so a later scan can attribute stale metadata such as `m_nameLookupTag` to another map without valid world info. `resetMap()` does not clear that parsed state; clear it on failure along with the other map state.
There was a problem hiding this comment.
resetMap now clears worldDict
…y or a map load fails
5a20064 to
7371b20
Compare
| if (!file.parse(nullptr)) | ||
| throw ERROR_CORRUPT_FILE_FORMAT; | ||
| } | ||
| catch (...) |
There was a problem hiding this comment.
throwing and catching in the same method is imho not a very good design.
| char *buffer = nullptr; | ||
| try | ||
| { | ||
| buffer = NEW char[ fileSize ]; |
| if( file->read( buffer, fileSize ) < fileSize ) | ||
| { | ||
| DEBUG_CRASH(( "copyFromBigToDir - Error reading from file '%s'", infile.str() )); | ||
| file->close(); |
There was a problem hiding this comment.
Shouldn't this be called before debug_crash? Otherwise in debug the file isn't closed.
| DEBUG_CRASH(( "copyFromBigToDir - Error writing to file '%s'", outfile.str() )); | ||
| if( filenew ) | ||
| filenew->close(); | ||
| delete [] buffer; |
There was a problem hiding this comment.
nit: whiteline before delete [] buffer; for readablity
copyFromBigToDirextracts a map's preview image into the user folder and throws on failure. Every throw left the source file open, and the read and write failures also left the 50 to 70 KB buffer behind.getMapPreviewImageswallows the throw and never caches the result, so the leak repeats on every preview request for that map.This bites whenever writing to the user folder fails: a Documents folder that OneDrive is syncing (#458), a read-only or full disk, or a preview locked by an antivirus scan. Each map browsed in the skirmish or LAN picker then costs a file handle and a buffer, again on every refresh.
loadMapin the map cache scan allocated the waypoint map and threw on a corrupt file without releasing it. A half-transferred map from a LAN game or a broken download in the maps folder leaked the previous map's data on every scan, and its tech and supply positions carried over into the next map's cache entry.Every failure path now closes the files and frees the buffers, and a corrupt map resets the scan state before throwing.