System.Data.SQLite
Check-in [659d427be4]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix memory leak with crypt keys
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 659d427be4dd6ffce3a792e7c944d78220a0763b
User & Date: rmsimpson 2006-01-12 20:53:00
Context
2006-01-12
20:53
Automate fixing up of sqlite sources check-in: f89ae9878e user: rmsimpson tags: sourceforge
20:53
Fix memory leak with crypt keys check-in: 659d427be4 user: rmsimpson tags: sourceforge
20:51
Jan 12 SQLite CVS HEAD check-in: 0ca16298cf user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/crypt.c.

            1  +#ifdef SQLITE_HAS_CODEC
            2  +  void sqlite3pager_free_codecarg(void *pArg);
            3  +#endif
            4  +
     1      5   #include "src/pager.c"
     2      6   
     3      7   #ifndef SQLITE_OMIT_DISKIO
     4      8   #ifdef SQLITE_HAS_CODEC
     5      9   
     6     10   #include <windows.h>
     7     11   #include <wincrypt.h>
     8     12   
     9         -HCRYPTPROV g_hProvider = 0; // Global instance of the cryptographic provider
    10         -
    11         -#define SQLITECRYPTERROR_PROVIDER "Cryptographic provider not available"
    12         -
    13     13   typedef struct _CRYPTBLOCK
    14     14   {
    15     15     HCRYPTKEY hReadKey;     // Key used to read from the database and write to the journal
    16     16     HCRYPTKEY hWriteKey;    // Key used to write to the database
    17     17     DWORD     dwPageSize;   // Size of pages
    18     18     LPVOID    pvCrypt;      // A buffer for encrypting/decrypting (if necessary)
    19     19     DWORD     dwCryptSize;  // Equal to or greater than dwPageSize.  If larger, pvCrypt is valid and this is its size
    20     20   } CRYPTBLOCK, *LPCRYPTBLOCK;
           21  +
           22  +HCRYPTPROV g_hProvider = 0; // Global instance of the cryptographic provider
           23  +
           24  +#define SQLITECRYPTERROR_PROVIDER "Cryptographic provider not available"
    21     25   
    22     26   // Needed for re-keying
    23     27   static void * sqlite3pager_get_codecarg(Pager *pPager)
    24     28   {
    25     29     return (pPager->xCodec) ? pPager->pCodecArg: NULL;
    26     30   }
    27     31   
................................................................................
   246    250     {
   247    251       LPCRYPTBLOCK pBlock = CreateCryptBlock(hKey, sqlite3BtreePager(db->aDb[nDb].pBt), NULL);
   248    252       sqlite3pager_set_codec(sqlite3BtreePager(db->aDb[nDb].pBt), sqlite3Codec, pBlock);
   249    253       rc = SQLITE_OK;
   250    254     }
   251    255     return rc;
   252    256   }
          257  +
          258  +void sqlite3pager_free_codecarg(void *pArg)
          259  +{
          260  +  LPCRYPTBLOCK pBlock = (LPCRYPTBLOCK)pArg;
          261  +
          262  +  if (pBlock)
          263  +  {
          264  +    if (pBlock->hReadKey)
          265  +      CryptDestroyKey(pBlock->hReadKey);
          266  +    if (pBlock->hWriteKey)
          267  +      CryptDestroyKey(pBlock->hWriteKey);
          268  +
          269  +    if (pBlock->pvCrypt)
          270  +      free(pBlock->pvCrypt);
          271  +  }
          272  +  free(pBlock);
          273  +}
   253    274   
   254    275   // Once a password has been supplied and a key created, we don't keep the 
   255    276   // original password for security purposes.  Therefore return NULL.
   256    277   void sqlite3CodecGetKey(sqlite3 *db, int nDb, void **ppKey, int *pnKeyLen)
   257    278   {
   258    279     *ppKey = NULL;
   259    280     *pnKeyLen = 0;