Alan,
I notice your fix for the cppcheck detected issues makes use of goto's. In many
circles use of goto is considered a real no-no. I'm not sure my fix of using a
macro for checking error codes and cleaning up is any better (see recent fix to
lib/nistcd/cdexpert.c), but we should perhaps have a coding policy on such
things to go along with our style policy.
Any thoughts from other developers?
Andrew
On Thu, Dec 10, 2009 at 08:18:54PM +0000, airwin@... wrote:
> Revision: 10718
> http://plplot.svn.sourceforge.net/plplot/?rev=10718&view=rev
> Author: airwin
> Date: 2009-12-10 20:18:54 +0000 (Thu, 10 Dec 2009)
>
> Log Message:
> -----------
> Get rid of memory leaks that would occur for error conditions.
> (Issue found by cppcheck).
>
> Modified Paths:
> --------------
> trunk/bindings/tcl/tclAPI.c
>
> Modified: trunk/bindings/tcl/tclAPI.c
> ===================================================================
> --- trunk/bindings/tcl/tclAPI.c 2009-12-10 19:53:30 UTC (rev 10717)
> +++ trunk/bindings/tcl/tclAPI.c 2009-12-10 20:18:54 UTC (rev 10718)
> @@ -640,6 +640,7 @@
> pls_auto_path( Tcl_Interp *interp )
> {
> char *buf, *ptr = NULL, *dn;
> + int return_code = TCL_OK;
> #ifdef DEBUG
> char *path;
> #endif
> @@ -651,7 +652,10 @@
> #ifdef TCL_DIR
> Tcl_SetVar( interp, "dir", TCL_DIR, TCL_GLOBAL_ONLY );
> if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR )
> - return TCL_ERROR;
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> #ifdef DEBUG
> fprintf( stderr, "adding %s to auto_path\n", TCL_DIR );
> path = Tcl_GetVar( interp, "auto_path", 0 );
> @@ -666,7 +670,10 @@
> plGetName( dn, "tcl", "", &ptr );
> Tcl_SetVar( interp, "dir", ptr, 0 );
> if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR )
> - return TCL_ERROR;
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> #ifdef DEBUG
> fprintf( stderr, "adding %s to auto_path\n", ptr );
> path = Tcl_GetVar( interp, "auto_path", 0 );
> @@ -682,7 +689,10 @@
> plGetName( dn, "", "", &ptr );
> Tcl_SetVar( interp, "dir", ptr, 0 );
> if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR )
> - return TCL_ERROR;
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> #ifdef DEBUG
> fprintf( stderr, "adding %s to auto_path\n", ptr );
> path = Tcl_GetVar( interp, "auto_path", 0 );
> @@ -699,7 +709,10 @@
> plGetName( dn, "tcl", "", &ptr );
> Tcl_SetVar( interp, "dir", ptr, 0 );
> if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR )
> - return TCL_ERROR;
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> #ifdef DEBUG
> fprintf( stderr, "adding %s to auto_path\n", ptr );
> path = Tcl_GetVar( interp, "auto_path", 0 );
> @@ -713,19 +726,26 @@
> if ( getcwd( buf, 256 ) == 0 )
> {
> Tcl_SetResult( interp, "Problems with getcwd in pls_auto_path", TCL_STATIC );
> - return TCL_ERROR;
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> }
> -
> Tcl_SetVar( interp, "dir", buf, 0 );
> if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR )
> - return TCL_ERROR;
> -
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> /*** see if plserver was invoked in the build tree ***/
> if ( plInBuildTree())
> {
> Tcl_SetVar( interp, "dir", BUILD_DIR "/bindings/tk", TCL_GLOBAL_ONLY );
> if ( tcl_cmd( interp, "set auto_path \"$dir $auto_path\"" ) == TCL_ERROR )
> - return TCL_ERROR;
> + {
> + return_code = TCL_ERROR;
> + goto finish;
> + }
> }
>
> #ifdef DEBUG
> @@ -734,10 +754,10 @@
> fprintf( stderr, "auto_path is %s\n", path );
> #endif
>
> - free_mem( buf );
> +finish: free_mem( buf );
> free_mem( ptr );
>
> - return TCL_OK;
> + return return_code;
> }
>
> /*----------------------------------------------------------------------*\
>
>
> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
>
> ------------------------------------------------------------------------------
> Return on Information:
> Google Enterprise Search pays you back
> Get the facts.
> http://p.sf.net/sfu/google-dev2dev
> _______________________________________________
> Plplot-cvs mailing list
> Plplot-cvs@...
> https://lists.sourceforge.net/lists/listinfo/plplot-cvs
>
----- End forwarded message -----
|