OSDN Git Service

Fix memory leak in upgrade_crypt_ftr
authorHenrik Baard <henrik.baard@sonymobile.com>
Thu, 5 Feb 2015 14:09:17 +0000 (15:09 +0100)
committerHenrik Baard <henrik.baard@sonymobile.com>
Thu, 5 Feb 2015 14:09:17 +0000 (15:09 +0100)
The structure crypt_persist_data was allocated,
but never freed.

Added free of allocated memory in normal and
error case.

Change-Id: I9aaa067e6f6501e8ce007f8659004b5dbcf2b246

cryptfs.c

index aaa2b86..534f0c0 100644 (file)
--- a/cryptfs.c
+++ b/cryptfs.c
@@ -567,6 +567,7 @@ static void upgrade_crypt_ftr(int fd, struct crypt_mnt_ftr *crypt_ftr, off64_t o
         /* Need to initialize the persistent data area */
         if (lseek64(fd, pdata_offset, SEEK_SET) == -1) {
             SLOGE("Cannot seek to persisent data offset\n");
+            free(pdata);
             return;
         }
         /* Write all zeros to the first copy, making it invalid */
@@ -581,6 +582,7 @@ static void upgrade_crypt_ftr(int fd, struct crypt_mnt_ftr *crypt_ftr, off64_t o
         crypt_ftr->persist_data_offset[0] = pdata_offset;
         crypt_ftr->persist_data_offset[1] = pdata_offset + CRYPT_PERSIST_DATA_SIZE;
         crypt_ftr->minor_version = 1;
+        free(pdata);
     }
 
     if ((crypt_ftr->major_version == 1) && (crypt_ftr->minor_version == 1)) {