From: <and...@us...> - 2009-11-16 12:03:17
|
Revision: 10596 http://plplot.svn.sourceforge.net/plplot/?rev=10596&view=rev Author: andrewross Date: 2009-11-16 12:03:10 +0000 (Mon, 16 Nov 2009) Log Message: ----------- Replace use of tmpnam in tk bindings with pl_create_tempfile. Note we need to retrieve the file name since the temporary metafile will be processed by plrender to create the output. Modified Paths: -------------- trunk/bindings/tk/plframe.c trunk/bindings/tk-x-plat/plplotter.c trunk/src/plstdio.c Modified: trunk/bindings/tk/plframe.c =================================================================== --- trunk/bindings/tk/plframe.c 2009-11-16 12:01:06 UTC (rev 10595) +++ trunk/bindings/tk/plframe.c 2009-11-16 12:03:10 UTC (rev 10596) @@ -2812,15 +2812,18 @@ } /* Open file for writes */ + sfnam = NULL; - sfnam = (char *) tmpnam( NULL ); - - if (( sfile = fopen( sfnam, "wb+" )) == NULL ) + /* Create and open temporary file */ + /* NB use fdopen to get a file stream from the existing file handle */ + if (( sfile = fdopen( pl_create_tempfile( &sfnam ) , "wb+" )) == NULL ) { Tcl_AppendResult( interp, "Error -- cannot open plot file for writing", (char *) NULL ); plend1(); + if (sfnam != NULL) + free(sfnam); return TCL_ERROR; } @@ -2857,10 +2860,13 @@ (char *) 0 )) { fprintf( stderr, "Unable to exec print command.\n" ); + free(sfnam); _exit( 1 ); } } + free(sfnam); + return result; } Modified: trunk/bindings/tk-x-plat/plplotter.c =================================================================== --- trunk/bindings/tk-x-plat/plplotter.c 2009-11-16 12:01:06 UTC (rev 10595) +++ trunk/bindings/tk-x-plat/plplotter.c 2009-11-16 12:03:10 UTC (rev 10596) @@ -2638,14 +2638,16 @@ /* Open file for writes */ - sfnam = (char *) tmpnam( NULL ); - - if (( sfile = fopen( sfnam, "wb+" )) == NULL ) + /* Create and open temporary file */ + /* NB use fdopen to get a file stream from the existing file handle */ + if (( sfile = fdopen( pl_create_tempfile(&sfnam), "wb+" )) == NULL ) { Tcl_AppendResult( interp, "Error -- cannot open plot file for writing", (char *) NULL ); plend1(); + if (sfnam != NULL) + free(sfnam); return TCL_ERROR; } @@ -2681,10 +2683,12 @@ (char *) 0 )) { fprintf( stderr, "Unable to exec print command.\n" ); + free(sfnam); _exit( 1 ); } } #endif + free(sfnam); return result; } Modified: trunk/src/plstdio.c =================================================================== --- trunk/src/plstdio.c 2009-11-16 12:01:06 UTC (rev 10595) +++ trunk/src/plstdio.c 2009-11-16 12:03:10 UTC (rev 10596) @@ -197,7 +197,7 @@ } /* N.B. Malloc ensures template is long enough so strcpy and strcat are safe here */ - template = (char *) malloc( strlen(tmpdir) + strlen(tmpfile) + 2); + template = (char *) malloc( sizeof(char)*(strlen(tmpdir) + strlen(tmpfile) + 2)); strcpy(template,tmpdir); #if defined ( MSDOS ) || defined ( WIN32 ) strcat(template,"\\"); @@ -210,7 +210,7 @@ fd = mkstemp(template); /* If we are not returning the file name then unlink the file so it is * automatically deleted. */ - if ( fd != -1 && fname != NULL ) + if ( fd != -1 && fname == NULL ) unlink(template); #else #if !defined(_S_IREAD) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |