Re: mkstemp in Player::AddTheme

Kristian Kvilekval <[email protected]>
Newsgroups gmane.comp.audio.zinf.devel
Message-ID <1047883722.849.139.camel@krispc>
On Sun, 2003-03-16 at 21:31, Tim Lesher wrote:
> It looks like mkstemp() is being misused in Player::AddTheme:
> 
> Player::AddTheme looks like this:
> 
> ---
> void Player::AddTheme(const char *url)
> {
>     string     szSavedTheme, szNewTheme;
>     char       *pTempFile = new char[13];
>     
>     m_context->prefs->GetPrefString(kThemePref, szSavedTheme);
>     URLToFilePath(url, szNewTheme); 
>     strncpy(pTempFile,"themeXXXXXX",13);
>     mkstemp (pTempFile);
>     if (CopyFile(szNewTheme.c_str(), pTempFile, false))
>         AcceptEvent(new LoadThemeEvent(pTempFile, 
>         szSavedTheme.c_str()));
>     delete [] pTempFile;
> }
> ---
> 
> mkstemp() actually opens the file with O_EXCL, returning an fd.  Am I
> missing something obvious, or will this leak the fd?  
> 
> The only reason I know for using mkstemp() over mktemp() is when you
> want to actually use the fd in writing to avoid the well-known
> mktemp() race condition.  If we're not doing that, any reason this
> shouldn't just call mktemp(), which is POSIX-standard?

Nope, looks like a bug.. gcc  gives a warning every time 
it encountered mktemp.. My docs say to use tmpnam.


-- 
Kristian G. Kvilekval
email:[email protected] office:(805)893-4276 http://www.cs.ucsb.edu/~kris



-------------------------------------------------------
This SF.net email is sponsored by:Crypto Challenge is now open! 
Get cracking and register here for some mind boggling fun and 
the chance of winning an Apple iPod:
http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0031en
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.