Fix error handling in CursorWindow
If a CursorWindow is created from a Parcel but the file descriptor is invalid or the mmap() call fails, the CursorWindow destructor will be invoked with an inconsistent object. The destructor will attempt to call munmap() with an unconfigured mData attribute. This makes two changes. First, the destructor only attempts to unmap memory if the file descriptor is non-negative. The old code unmapped memory if the file descriptor was not -1. However, the construction code treated any negative file descriptor as an error. Second, when a CursorWindow is created from a parcel, the file descriptor field is not changed from -1 (the constructor default) until it is known that the memory mapping has succeeded. If the function exits early, it is no longer in a half-constructed state. As a bonus, if mmap() fails in the method, the duplicated file descriptor is closed rather than leaked. Flag: EXEMPT bug-fix Bug: 330108840 Test: atest * libandroidfw_tests Change-Id: I94a9240dbd06b255bff9491ea390b485bac3cb88
Loading
Please register or sign in to comment