/ Check-in [50fbcdea]
Login

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

Overview
Comment:Another change related to (6401) and (6402): When an attempt to unlock a file fails in os_unix.c, close all files held open waiting for the unlock event anyway. This prevents a file-descriptor leak when testing IO errors. (CVS 6406)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 50fbcdea045f7d4266d9afa721616c720564aa93
User & Date: danielk1977 2009-03-30 07:39:35
Context
2009-03-30
11:59
Display a warning that the notify2-3 test sometimes fails on single-core machines. (CVS 6407) check-in: ab7c718d user: drh tags: trunk
07:39
Another change related to (6401) and (6402): When an attempt to unlock a file fails in os_unix.c, close all files held open waiting for the unlock event anyway. This prevents a file-descriptor leak when testing IO errors. (CVS 6406) check-in: 50fbcdea user: danielk1977 tags: trunk
2009-03-29
15:12
Add a comment to the doubleToInt64() routine that explains why returning minInt is in fact correct when it seems like maxInt should be returned. (CVS 6405) check-in: 7f3be360 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

    39     39   **   *  Definitions of sqlite3_io_methods objects for all locking
    40     40   **      methods plus "finder" functions for each locking method.
    41     41   **   *  sqlite3_vfs method implementations.
    42     42   **   *  Locking primitives for the proxy uber-locking-method. (MacOSX only)
    43     43   **   *  Definitions of sqlite3_vfs objects for all locking methods
    44     44   **      plus implementations of sqlite3_os_init() and sqlite3_os_end().
    45     45   **
    46         -** $Id: os_unix.c,v 1.247 2009/03/28 23:47:11 drh Exp $
           46  +** $Id: os_unix.c,v 1.248 2009/03/30 07:39:35 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #if SQLITE_OS_UNIX              /* This file is used on unix only */
    50     50   
    51     51   /*
    52     52   ** There are various methods for file locking used for concurrency
    53     53   ** control:
................................................................................
  1455   1455           pFile->lastErrno = tErrno;
  1456   1456         }
  1457   1457         goto end_unlock;
  1458   1458       }
  1459   1459     }
  1460   1460     if( locktype==NO_LOCK ){
  1461   1461       struct unixOpenCnt *pOpen;
         1462  +    int rc2 = SQLITE_OK;
  1462   1463   
  1463   1464       /* Decrement the shared lock counter.  Release the lock using an
  1464   1465       ** OS call only when all threads in this same process have released
  1465   1466       ** the lock.
  1466   1467       */
  1467   1468       pLock->cnt--;
  1468   1469       if( pLock->cnt==0 ){
................................................................................
  1476   1477           pLock->locktype = NO_LOCK;
  1477   1478         }else{
  1478   1479           int tErrno = errno;
  1479   1480           rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_UNLOCK);
  1480   1481           if( IS_LOCK_ERROR(rc) ){
  1481   1482             pFile->lastErrno = tErrno;
  1482   1483           }
  1483         -        pLock->cnt = 1;
  1484   1484           pLock->locktype = NO_LOCK;
  1485   1485           pFile->locktype = NO_LOCK;
  1486         -        goto end_unlock;
  1487   1486         }
  1488   1487       }
  1489   1488   
  1490   1489       /* Decrement the count of locks against this same file.  When the
  1491   1490       ** count reaches zero, close any other file descriptors whose close
  1492   1491       ** was deferred because of outstanding locks.
  1493   1492       */
         1493  +    pOpen = pFile->pOpen;
         1494  +    pOpen->nLock--;
         1495  +    assert( pOpen->nLock>=0 );
         1496  +    if( pOpen->nLock==0 && pOpen->nPending>0 ){
         1497  +      int i;
         1498  +      for(i=0; i<pOpen->nPending; i++){
         1499  +        /* close pending fds, but if closing fails don't free the array
         1500  +        ** assign -1 to the successfully closed descriptors and record the
         1501  +        ** error.  The next attempt to unlock will try again. */
         1502  +        if( pOpen->aPending[i] < 0 ) continue;
         1503  +        if( close(pOpen->aPending[i]) ){
         1504  +          pFile->lastErrno = errno;
         1505  +          rc2 = SQLITE_IOERR_CLOSE;
         1506  +        }else{
         1507  +          pOpen->aPending[i] = -1;
         1508  +        }
         1509  +      }
         1510  +      if( rc2==SQLITE_OK ){
         1511  +        sqlite3_free(pOpen->aPending);
         1512  +        pOpen->nPending = 0;
         1513  +        pOpen->aPending = 0;
         1514  +      }
         1515  +    }
  1494   1516       if( rc==SQLITE_OK ){
  1495         -      pOpen = pFile->pOpen;
  1496         -      pOpen->nLock--;
  1497         -      assert( pOpen->nLock>=0 );
  1498         -      if( pOpen->nLock==0 && pOpen->nPending>0 ){
  1499         -        int i;
  1500         -        for(i=0; i<pOpen->nPending; i++){
  1501         -          /* close pending fds, but if closing fails don't free the array
  1502         -          ** assign -1 to the successfully closed descriptors and record the
  1503         -          ** error.  The next attempt to unlock will try again. */
  1504         -          if( pOpen->aPending[i] < 0 ) continue;
  1505         -          if( close(pOpen->aPending[i]) ){
  1506         -            pFile->lastErrno = errno;
  1507         -            rc = SQLITE_IOERR_CLOSE;
  1508         -          }else{
  1509         -            pOpen->aPending[i] = -1;
  1510         -          }
  1511         -        }
  1512         -        if( rc==SQLITE_OK ){
  1513         -          sqlite3_free(pOpen->aPending);
  1514         -          pOpen->nPending = 0;
  1515         -          pOpen->aPending = 0;
  1516         -        }
  1517         -      }
         1517  +      rc = rc2;
  1518   1518       }
  1519   1519     }
  1520   1520   	
  1521   1521   end_unlock:
  1522   1522     unixLeaveMutex();
  1523   1523     if( rc==SQLITE_OK ) pFile->locktype = locktype;
  1524   1524     return rc;