/ Check-in [e01c5f3eda]
Login

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

Overview
Comment:fixed memory leak in proxy lock file error handling
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA1: e01c5f3eda7fe6e6afe9c3894384f09b58173da1
User & Date: adam 2010-09-10 23:16:17
Context
2010-11-09
00:43
Integrated proxy locking file support for WAL journal mode and double free fix check-in: fd4d38fa66 user: adam tags: apple-osx
2010-09-10
23:16
fixed memory leak in proxy lock file error handling check-in: e01c5f3eda user: adam tags: apple-osx
20:19
replaced relative lock proxy paths with absolute check-in: 782c33512a user: adam tags: apple-osx
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

2804
2805
2806
2807
2808
2809
2810






2811
2812
2813
2814
2815
2816
2817
....
2863
2864
2865
2866
2867
2868
2869








2870

2871
2872
2873
2874
2875
2876
2877
....
5551
5552
5553
5554
5555
5556
5557

5558
5559
5560
5561
5562
5563
5564
....
5581
5582
5583
5584
5585
5586
5587

5588
5589
5590
5591
5592
5593
5594
*/
#ifdef F_FULLFSYNC
# define HAVE_FULLFSYNC 1
#else
# define HAVE_FULLFSYNC 0
#endif








/*
** The fsync() system call does not work as advertised on many
** unix systems.  The following procedure is an attempt to make
** it work better.
**
** The SQLITE_NO_SYNC macro disables all fsync()s.  This is useful
................................................................................
  /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
  ** no-op
  */
#ifdef SQLITE_NO_SYNC
  rc = SQLITE_OK;
#elif HAVE_FULLFSYNC
  if( fullSync ){








    rc = fcntl(fd, F_FULLFSYNC, 0);

  }else{
    rc = 1;
  }
  /* If the FULLFSYNC failed, fall back to attempting an fsync().
  ** It shouldn't be possible for fullfsync to fail on the local 
  ** file system (on OSX), so failure indicates that FULLFSYNC
  ** isn't supported for this file system. So, attempt an fsync 
................................................................................
  }
  if( fd<0 ){
    openFlags = O_RDONLY;
    fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
    terrno = errno;
  }
  if( fd<0 ){

    if( islockfile ){
      return SQLITE_BUSY;
    }
    switch (terrno) {
      case EACCES:
        return SQLITE_PERM;
      case EIO: 
................................................................................
  pNew->pUnused = pUnused;
  
  rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0);
  if( rc==SQLITE_OK ){
    *ppFile = pNew;
    return SQLITE_OK;
  }

end_create_proxy:    
  close(fd); /* silently leak fd if error, we're already in error */
  sqlite3_free(pNew);
  sqlite3_free(pUnused);
  return rc;
}








>
>
>
>
>
>







 







>
>
>
>
>
>
>
>

>







 







>







 







>







2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
....
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
....
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
....
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
*/
#ifdef F_FULLFSYNC
# define HAVE_FULLFSYNC 1
#else
# define HAVE_FULLFSYNC 0
#endif

#ifdef SQLITE_USE_REQUEST_FULLFSYNC
#import <notify.h>
#import <libkern/OSAtomic.h>
static OSSpinLock notify_lock = 0;
#define REQUEST_FULLSYNC_NOTIFICATION    "com.apple.reqsync"
#endif

/*
** The fsync() system call does not work as advertised on many
** unix systems.  The following procedure is an attempt to make
** it work better.
**
** The SQLITE_NO_SYNC macro disables all fsync()s.  This is useful
................................................................................
  /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a
  ** no-op
  */
#ifdef SQLITE_NO_SYNC
  rc = SQLITE_OK;
#elif HAVE_FULLFSYNC
  if( fullSync ){
#ifdef SQLITE_USE_REQUEST_FULLFSYNC
    rc = fsync(fd);
    if (!rc) {
      OSSpinLockLock(&notify_lock);
      rc = notify_post(REQUEST_FULLSYNC_NOTIFICATION);
      OSSpinLockUnlock(&notify_lock);
    }
#else
    rc = fcntl(fd, F_FULLFSYNC, 0);
#endif
  }else{
    rc = 1;
  }
  /* If the FULLFSYNC failed, fall back to attempting an fsync().
  ** It shouldn't be possible for fullfsync to fail on the local 
  ** file system (on OSX), so failure indicates that FULLFSYNC
  ** isn't supported for this file system. So, attempt an fsync 
................................................................................
  }
  if( fd<0 ){
    openFlags = O_RDONLY;
    fd = open(path, openFlags, SQLITE_DEFAULT_FILE_PERMISSIONS);
    terrno = errno;
  }
  if( fd<0 ){
    sqlite3_free(pUnused);
    if( islockfile ){
      return SQLITE_BUSY;
    }
    switch (terrno) {
      case EACCES:
        return SQLITE_PERM;
      case EIO: 
................................................................................
  pNew->pUnused = pUnused;
  
  rc = fillInUnixFile(&dummyVfs, fd, dirfd, (sqlite3_file*)pNew, path, 0, 0);
  if( rc==SQLITE_OK ){
    *ppFile = pNew;
    return SQLITE_OK;
  }
  sqlite3_free(pNew->pUnused);
end_create_proxy:    
  close(fd); /* silently leak fd if error, we're already in error */
  sqlite3_free(pNew);
  sqlite3_free(pUnused);
  return rc;
}