SQLite

Check-in [ad8f12cad1]
Login

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

Overview
Comment:Closing a file from the wrong thread is harmless on most systems. (See ticket #1611) But on systems like RedHat9 with broken fcntl() locks, it leaks file descriptors. That is better than the alternative of prematurely breaking locks and causing database corruption. Nevertheless, it would be good if we could figure out a way to report errors when closing a file from the wrong thread. (CVS 2946)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ad8f12cad1fcd9c54478abe20050f9a953035506
User & Date: drh 2006-01-15 02:43:16.000
Context
2006-01-15
11:39
Rollback any open write-transaction when a shared-cache connection is closed. (CVS 2947) (check-in: 1944d92b53 user: danielk1977 tags: trunk)
02:43
Closing a file from the wrong thread is harmless on most systems. (See ticket #1611) But on systems like RedHat9 with broken fcntl() locks, it leaks file descriptors. That is better than the alternative of prematurely breaking locks and causing database corruption. Nevertheless, it would be good if we could figure out a way to report errors when closing a file from the wrong thread. (CVS 2946) (check-in: ad8f12cad1 user: drh tags: trunk)
02:30
Add tests and fix bugs in the new cross-thread lock resolution code. When an unlock fails, do not leak file descriptors (ticket #1611). But we really ought to report SQLITE_MISUSE or some other error instead of just returning SQLITE_OK. (CVS 2945) (check-in: f68e05cb2b user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/os_unix.c.
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
** Close a file.
*/
static int unixClose(OsFile **pId){
  unixFile *id = (unixFile*)*pId;
  int rc;

  if( !id ) return SQLITE_OK;
  rc = unixUnlock(*pId, NO_LOCK);
  if( id->dirfd>=0 ) close(id->dirfd);
  id->dirfd = -1;
  sqlite3OsEnterMutex();

  if( id->pOpen->nLock && rc==SQLITE_OK ){
    /* If there are outstanding locks, do not actually close the file just
    ** yet because that would clear those locks.  Instead, add the file
    ** descriptor to pOpen->aPending.  It will be automatically closed when
    ** the last lock is cleared.
    */
    int *aNew;
    struct openCnt *pOpen = id->pOpen;







|




|







1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
** Close a file.
*/
static int unixClose(OsFile **pId){
  unixFile *id = (unixFile*)*pId;
  int rc;

  if( !id ) return SQLITE_OK;
  unixUnlock(*pId, NO_LOCK);
  if( id->dirfd>=0 ) close(id->dirfd);
  id->dirfd = -1;
  sqlite3OsEnterMutex();

  if( id->pOpen->nLock ){
    /* If there are outstanding locks, do not actually close the file just
    ** yet because that would clear those locks.  Instead, add the file
    ** descriptor to pOpen->aPending.  It will be automatically closed when
    ** the last lock is cleared.
    */
    int *aNew;
    struct openCnt *pOpen = id->pOpen;
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509

  sqlite3OsLeaveMutex();
  id->isOpen = 0;
  TRACE2("CLOSE   %-3d\n", id->h);
  OpenCounter(-1);
  sqliteFree(id);
  *pId = 0;
  return SQLITE_OK;
}

/*
** Turn a relative pathname into a full pathname.  Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.







|







1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509

  sqlite3OsLeaveMutex();
  id->isOpen = 0;
  TRACE2("CLOSE   %-3d\n", id->h);
  OpenCounter(-1);
  sqliteFree(id);
  *pId = 0;
  return rc;
}

/*
** Turn a relative pathname into a full pathname.  Return a pointer
** to the full pathname stored in space obtained from sqliteMalloc().
** The calling function is responsible for freeing this space once it
** is no longer needed.