/ Check-in [2470d1bb]
Login

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

Overview
Comment:Fix memory/resource leaks for WinCE and Cygwin.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | wince-fixes
Files: files | file ages | folders
SHA1: 2470d1bb08b2661bcfde7a605208eb6044836d5c
User & Date: mistachkin 2013-10-16 09:49:10
Context
2013-10-16
11:31
Fix memory and resource leaks for WinCE and Cygwin, and a compiler warning on windows with SQLITE_THREADSAFE=0. check-in: 9905cea9 user: drh tags: trunk
09:49
Fix memory/resource leaks for WinCE and Cygwin. Closed-Leaf check-in: 2470d1bb user: mistachkin tags: wince-fixes
2013-10-15
19:06
Add the "languageid" hidden column to fts4aux. check-in: 891df358 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_win.c.

  2192   2192   #ifndef SQLITE_OMIT_WAL
  2193   2193     assert( pFile->pShm==0 );
  2194   2194   #endif
  2195   2195     assert( pFile->h!=NULL && pFile->h!=INVALID_HANDLE_VALUE );
  2196   2196     OSTRACE(("CLOSE file=%p\n", pFile->h));
  2197   2197   
  2198   2198   #if SQLITE_MAX_MMAP_SIZE>0
  2199         -  rc = winUnmapfile(pFile);
  2200         -  if( rc!=SQLITE_OK ) return rc;
         2199  +  winUnmapfile(pFile);
  2201   2200   #endif
  2202   2201   
  2203   2202     do{
  2204   2203       rc = osCloseHandle(pFile->h);
  2205   2204       /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */
  2206   2205     }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) );
  2207   2206   #if SQLITE_OS_WINCE
................................................................................
  2999   2998         if( newLimit>sqlite3GlobalConfig.mxMmap ){
  3000   2999           newLimit = sqlite3GlobalConfig.mxMmap;
  3001   3000         }
  3002   3001         *(i64*)pArg = pFile->mmapSizeMax;
  3003   3002         if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
  3004   3003           pFile->mmapSizeMax = newLimit;
  3005   3004           if( pFile->mmapSize>0 ){
  3006         -          (void)winUnmapfile(pFile);
         3005  +          winUnmapfile(pFile);
  3007   3006             rc = winMapfile(pFile, -1);
  3008   3007           }
  3009   3008         }
  3010   3009         OSTRACE(("FCNTL file=%p, rc=%s\n", pFile->h, sqlite3ErrName(rc)));
  3011   3010         return rc;
  3012   3011       }
  3013   3012   #endif
................................................................................
  4069   4068         ** character, assume it is already a native Win32 path; otherwise,
  4070   4069         ** it must be converted to a native Win32 path prior via the Cygwin
  4071   4070         ** API prior to using it.
  4072   4071         */
  4073   4072         if( winIsDriveLetterAndColon(zDir) ){
  4074   4073           zConverted = winConvertFromUtf8Filename(zDir);
  4075   4074           if( !zConverted ){
         4075  +          sqlite3_free(zBuf);
  4076   4076             OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4077   4077             return SQLITE_IOERR_NOMEM;
  4078   4078           }
  4079   4079           if( winIsDir(zConverted) ){
  4080   4080             sqlite3_snprintf(nBuf-30, zBuf, "%s", zDir);
  4081   4081             sqlite3_free(zConverted);
  4082   4082             break;
  4083   4083           }
  4084   4084           sqlite3_free(zConverted);
  4085   4085         }else{
  4086   4086           zConverted = sqlite3MallocZero( nBuf+1 );
  4087   4087           if( !zConverted ){
         4088  +          sqlite3_free(zBuf);
  4088   4089             OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4089   4090             return SQLITE_IOERR_NOMEM;
  4090   4091           }
  4091   4092           if( cygwin_conv_path(
  4092   4093                   osIsNT() ? CCP_POSIX_TO_WIN_W : CCP_POSIX_TO_WIN_A, zDir,
  4093   4094                   zConverted, nBuf+1)<0 ){
  4094   4095             sqlite3_free(zConverted);
         4096  +          sqlite3_free(zBuf);
  4095   4097             OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_CONVPATH\n"));
  4096   4098             return winLogError(SQLITE_IOERR_CONVPATH, (DWORD)errno,
  4097   4099                                "winGetTempname1", zDir);
  4098   4100           }
  4099   4101           if( winIsDir(zConverted) ){
  4100   4102             /* At this point, we know the candidate directory exists and should
  4101   4103             ** be used.  However, we may need to convert the string containing
  4102   4104             ** its name into UTF-8 (i.e. if it is UTF-16 right now).
  4103   4105             */
  4104   4106             if( osIsNT() ){
  4105   4107               char *zUtf8 = winUnicodeToUtf8(zConverted);
  4106   4108               if( !zUtf8 ){
  4107   4109                 sqlite3_free(zConverted);
         4110  +              sqlite3_free(zBuf);
  4108   4111                 OSTRACE(("TEMP-FILENAME rc=SQLITE_IOERR_NOMEM\n"));
  4109   4112                 return SQLITE_IOERR_NOMEM;
  4110   4113               }
  4111   4114               sqlite3_snprintf(nBuf-30, zBuf, "%s", zUtf8);
  4112   4115               sqlite3_free(zUtf8);
  4113   4116               sqlite3_free(zConverted);
  4114   4117               break;
................................................................................
  4116   4119               sqlite3_snprintf(nBuf-30, zBuf, "%s", zConverted);
  4117   4120               sqlite3_free(zConverted);
  4118   4121               break;
  4119   4122             }
  4120   4123           }
  4121   4124           sqlite3_free(zConverted);
  4122   4125         }
  4123         -      break;
  4124   4126       }
  4125   4127     }
  4126   4128   #elif !SQLITE_OS_WINRT && !defined(__CYGWIN__)
  4127   4129     else if( osIsNT() ){
  4128   4130       char *zMulti;
  4129   4131       LPWSTR zWidePath = sqlite3MallocZero( nBuf*sizeof(WCHAR) );
  4130   4132       if( !zWidePath ){
................................................................................
  4486   4488     }
  4487   4489     if( isTemp ){
  4488   4490       pFile->zDeleteOnClose = zConverted;
  4489   4491     }else
  4490   4492   #endif
  4491   4493     {
  4492   4494       sqlite3_free(zConverted);
  4493         -    sqlite3_free(zTmpname);
  4494   4495     }
  4495   4496   
         4497  +  sqlite3_free(zTmpname);
  4496   4498     pFile->pMethod = &winIoMethod;
  4497   4499     pFile->pVfs = pVfs;
  4498   4500     pFile->h = h;
  4499   4501     if( isReadonly ){
  4500   4502       pFile->ctrlFlags |= WINFILE_RDONLY;
  4501   4503     }
  4502   4504     if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){