[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] Using KTempFile() instead of tmpnam() in
From:       Kevin Lo <kevlo () kde ! org>
Date:       2000-11-24 10:22:11
[Download RAW message or body]

Waldo Bastian wrote:

> On Thursday, November 23, 2000 20:20, Kevin Lo wrote:
> > Hi,
> >
> > This patch is to use KTempFile instead of tmpnam in kscd/CDDialog.cpp.
> > If no problem, I will commit it, thanks.
> >
> > - Kevin
>
> Are you sure this works? tmpfile.setAutoDelete(true) will delete the file when
> the tmpfile object gets destructed. Do you want that?
>
> Don't you want to use tmpfile.unlink() instead? Do you need to delete the
> file?
>
> You might want to use:
>     QString tempfile;
>     {
>        KTempFile tmpfile;
>        tempfile = tmpfile.name();
>     }
>     save_cddb_entry(tempfile,true);
>
> Assuming that save_cddb_entry doesn't mind writing to an already existing
> file. This is free of race conditions.

Hi Waldo,

I forgot to use unlink(), sorry about that. This patch is correct.
Thanks for correcting.

> Cheers,
> Waldo

- Kevin

["patch-CDDialog.cpp" (text/plain)]

--- kscd/CDDialog.cpp.orig	Fri Nov 24 18:13:01 2000
+++ kscd/CDDialog.cpp	Fri Nov 24 18:19:25 2000
@@ -30,6 +30,7 @@
 
 #include <kapp.h>
 #include <kmessagebox.h>
+#include <ktempfile.h>
 
 #include "CDDialog.h"
 #include "CDDialog.moc"
@@ -428,7 +429,10 @@
   delete dialog;
 
   QString tempfile;
-  tempfile = tmpnam(0L);
+  {
+    KTempFile tmpfile;
+    tempfile = tmpfile.name();
+  }
 
   save_cddb_entry(tempfile,true);
 
@@ -515,6 +519,7 @@
   file.close();
   //  file2.close();   // *****
 
+  tmpfile.unlink();
   unlink(QFile::encodeName(tempfile));
   kdDebug() << "DONE SENDING\n" << endl;
 } // upload


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic