This commit is contained in:
Darryl Miles 2026-05-30 03:19:20 +08:00 committed by GitHub
commit c69ad8efe7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 2 deletions

View File

@ -4819,7 +4819,6 @@ DBCellWrite(cellDef, fileName)
const char *cp1; const char *cp1;
char *cp2, *dotptr; char *cp2, *dotptr;
char expandbuf[NAME_SIZE]; char expandbuf[NAME_SIZE];
FILE *realf, *tmpf;
int tmpres; int tmpres;
struct stat statb; struct stat statb;
bool result, exists; bool result, exists;
@ -4951,6 +4950,7 @@ DBCellWrite(cellDef, fileName)
tmpname = StrDup((char **)NULL, expandname); tmpname = StrDup((char **)NULL, expandname);
} }
FILE *realf = NULL, *tmpf;
/* /*
* See if we can create a temporary file in this directory. * See if we can create a temporary file in this directory.
* If so, write to the temp file and then rename it after * If so, write to the temp file and then rename it after
@ -5081,6 +5081,7 @@ DBCellWrite(cellDef, fileName)
#endif #endif
realf = fopen(expandname, "r"); realf = fopen(expandname, "r");
bool do_close = FALSE;
if (realf == NULL) if (realf == NULL)
{ {
cellDef->cd_flags |= CDMODIFIED; cellDef->cd_flags |= CDMODIFIED;
@ -5097,15 +5098,26 @@ DBCellWrite(cellDef, fileName)
} }
#ifdef FILE_LOCKS #ifdef FILE_LOCKS
/* when file locking is in use the FD needs to stay open to hold the lock
* as with fcntl() locking any call to close() on any FD even dup() and
* those from separate open() calls, will cause all locks to be dropped
* by all FDs as they are process wide locks and associated with file
* system st_dev(kernel-device)/st_ino(inode) and not with FD handles.
*/
cellDef->cd_fd = -1; cellDef->cd_fd = -1;
if (FileLocking && (is_locked == FALSE)) if (FileLocking && (is_locked == FALSE))
cellDef->cd_fd = fd; cellDef->cd_fd = fd;
else if (FileLocking && (is_locked == TRUE)) else if (FileLocking && (is_locked == TRUE))
cellDef->cd_fd = -2; cellDef->cd_fd = -2;
else else
do_close = TRUE;
#else
do_close = TRUE;
#endif #endif
fclose(realf);
} }
if(do_close)
fclose(realf);
/* invalidate even if we don't close to ensure cleanup below does not close */
realf = NULL; realf = NULL;
} }
@ -5113,6 +5125,8 @@ cleanup:
SigEnableInterrupts(); SigEnableInterrupts();
freeMagic(realname); freeMagic(realname);
freeMagic(tmpname); freeMagic(tmpname);
if(realf)
fclose(realf);
return result; return result;
} }