diff options
-rw-r--r-- | bus.c | 2 | ||||
-rw-r--r-- | flash.c | 12 |
2 files changed, 11 insertions, 3 deletions
@@ -274,7 +274,7 @@ static int gpio_readvalue(unsigned base, unsigned io) gpio_getvaluenodepath(base, io, path); FILE* valuefile = fopen(path, "r"); if (valuefile != NULL) { - char value[2]; // value will be a single char and \n + char value[2]; // value will be a single char and \n fread(value, 1, 2, valuefile); fclose(valuefile); return atoi(value); @@ -1,6 +1,4 @@ #include "globals.h" -#include "lcd.h" -#include "version.h" #include <stdint.h> #include <stdio.h> #include <stdbool.h> @@ -118,6 +116,7 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in // create a buffer for the existing data void* payload = malloc(total); if (payload == NULL) { + close(fd); errno = PERSIST_ERR_COULDNTALLOCATEBUFFER; return false; } @@ -126,6 +125,8 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in persistencehdr hdr; if (read(fd, &hdr, sizeof(persistencehdr)) != sizeof(persistencehdr)) { errno = PERSIST_ERR_COULDNTREADHDR; + free(payload); + close(fd); return false; } @@ -133,6 +134,8 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in persistence_printheader(&hdr); if (read(fd, payload, total) != total) { errno = PERSIST_ERR_COULDNTREADDATA; + free(payload); + close(fd); return false; } @@ -140,6 +143,8 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in uint32_t calculatedcrc32 = crc32((uint8_t*) payload, hdr.length); if (calculatedcrc32 != hdr.crc32) { errno = PERSIST_ERR_BADCRC32; + free(payload); + close(fd); return false; } // overlay the payload with the existing data @@ -164,6 +169,7 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in // write the header if (write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) { errno = PERSIST_ERR_COULDNTWRITE; + close(fd); return false; } @@ -171,12 +177,14 @@ bool persistence_freeze(char* dest, void* data, unsigned int offset, unsigned in if (lseek(fd, offset, SEEK_CUR) < 0) { errno = PERSIST_ERR_COULDNTSEEK; // shouldn't ever happen really because if we're actually // seeking the file should already be the total size. + close(fd); return false; } // write the data out to disk if (write(fd, ((char*) data) + offset, len) != len) { errno = PERSIST_ERR_COULDNTWRITE; + close(fd); return false; } |