Preferences
Preferences copied to clipboard
Close the opened file before return out of function _fs_verify
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;
}