Sorry, another patch as the previous one omitted a sanity check that the
first patch had included.

The attached patch now has everything. It works on my system.

Ciao
Stephan

Am Mittwoch, den 26.05.2010, 13:35 +0200 schrieb Stephan Mueller:
> An update of the patch: I forgot to also close the directory file handle
> which leads to a file descriptor leak.
> 
> Furthermore, I removed the SysRemove() call as I think it is not
> necessary any more - the file is never created if it is not needed. and
> If it is needed, it should not be created.
> 
> Ciao
> Stephan
> 
> Am Mittwoch, den 26.05.2010, 11:42 +0200 schrieb Stephan Mueller:
> > Hi,
> > 
> > please see attached patch for LMAIL. It stops from creating tmp files if
> > there is no need to do so. This prevents excessive hdd access.
> > 
> > Though, there is one very minor issue - maybe you can help me: Since
> > SysRemove(pszSSFileName); is always called it usually calls unlink()
> > which returns in an strace an ENOENT (as the tmp file most of the time
> > does not exist). I think that this issue is negligible. Still, Davide,
> > can you please check whether we can simply remove that SysRemove() call
> > as the tmp file should have never been created with my patch when
> > iFileCount == 0?
> > 
> > Thanks
> > Stephan 
> > 
> > _______________________________________________
> > xmail mailing list
> > [email protected]
> > http://xmailserver.org/mailman/listinfo/xmail
> 
> _______________________________________________
> xmail mailing list
> [email protected]
> http://xmailserver.org/mailman/listinfo/xmail


--- LMAILSvr.cpp.orig	2010-05-26 08:49:02.000000000 +0200
+++ LMAILSvr.cpp	2010-05-26 17:09:08.000000000 +0200
@@ -116,6 +116,7 @@
 				 int iMaxSSFileName)
 {
 	char szSpoolDir[SYS_MAX_PATH];
+	FILE *pSSFile = NULL;
 
 	LMAILGetSpoolDir(szSpoolDir, sizeof(szSpoolDir));
 
@@ -129,14 +130,6 @@
 
 	UsrGetTmpFile(NULL, pszSSFileName, iMaxSSFileName);
 
-	FILE *pSSFile = fopen(pszSSFileName, "wb");
-
-	if (pSSFile == NULL) {
-		ErrorPush();
-		RLckUnlockSH(hResLock);
-		return ErrorPop();
-	}
-
 	int iFileCount = 0;
 	char szSpoolFileName[SYS_MAX_PATH];
 	FSCAN_HANDLE hFileScan = MscFirstFile(szSpoolDir, 0, szSpoolFileName,
@@ -149,17 +142,29 @@
 
 			if ((ulHashValue % (unsigned long) pLMAILCfg->lNumThreads) ==
 			    (unsigned long) lThreadId) {
+				if(pSSFile == NULL) {
+					pSSFile = fopen(pszSSFileName, "wb");
+
+					if (pSSFile == NULL) {
+						ErrorPush();
+						MscCloseFindFile(hFileScan);
+						RLckUnlockSH(hResLock);
+						return ErrorPop();
+					}
+				}
+
 				fprintf(pSSFile, "%s\r\n", szSpoolFileName);
 				++iFileCount;
 			}
 		} while (MscNextFile(hFileScan, szSpoolFileName, sizeof(szSpoolFileName)));
 		MscCloseFindFile(hFileScan);
 	}
-	fclose(pSSFile);
+
+	if(pSSFile != NULL)
+		fclose(pSSFile);
 	RLckUnlockSH(hResLock);
 
 	if (iFileCount == 0) {
-		SysRemove(pszSSFileName);
 		SetEmptyString(pszSSFileName);
 
 		ErrSetErrorCode(ERR_NO_LOCAL_SPOOL_FILES);
_______________________________________________
xmail mailing list
[email protected]
http://xmailserver.org/mailman/listinfo/xmail

Reply via email to