Preferences icon indicating copy to clipboard operation
Preferences copied to clipboard

Close the opened file before return out of function _fs_verify

Open tomphan opened this issue 5 months ago • 0 comments

I added the code before returning: close(fd); // should close here

static bool _fs_verify(const char* path, const void* buf, int bufsize) {
    int fd = open(path, O_RDONLY);
    if (fd >= 0) {
        struct stat st;
        stat(path, &st);
        if (st.st_size == bufsize && bufsize <= 1024) {
            // Check if content is the same
            uint8_t tmp[bufsize];
            if (read(fd, tmp, bufsize) == bufsize) {
                if (!memcmp(buf, tmp, bufsize)) {

                    close(fd);  // should close here

                    return true;
                }
            }
        }
        close(fd);
    }
    return false;
}

tomphan avatar Sep 10 '24 13:09 tomphan