SOURCES (rpm-4_4_9): rpm-lualeak.patch - more _free() compatible, ...

Tomasz Wittner tomasz.wittner at gmail.com
Mon Mar 17 22:44:29 CET 2008


On Monday 17 of March 2008, 21:12, glen wrote:
> Author: glen                         Date: Mon Mar 17 20:12:18 2008 GMT
> Module: SOURCES                       Tag: rpm-4_4_9
> ---- Log message:
> - more _free() compatible, however no luck still
>
> ---- Files affected:
> SOURCES:
>    rpm-lualeak.patch (1.1.2.1 -> 1.1.2.2)
>
> ---- Diffs:
>
> ================================================================
> Index: SOURCES/rpm-lualeak.patch
> diff -u SOURCES/rpm-lualeak.patch:1.1.2.1 SOURCES/rpm-lualeak.patch:1.1.2.2
> --- SOURCES/rpm-lualeak.patch:1.1.2.1	Mon Mar 17 20:25:50 2008
> +++ SOURCES/rpm-lualeak.patch	Mon Mar 17 21:12:13 2008
> @@ -6,7 +6,7 @@
>   	    lua_pushliteral(L, "LUA_PATH");
>   	    lua_pushstring(L, _lua_path);
>  -	    free(_lua_path);
> -+	    free(_lua_path); _lua_path = NULL;
> ++	    if (_lua_path) free(_lua_path); _lua_path = NULL;
>   	}
>       }
>       lua_rawset(L, LUA_GLOBALSINDEX);
> @@ -15,7 +15,7 @@
>   	    if (Stat(_lua_init, &st) != -1)
>   		(void)rpmluaRunScriptFile(lua, _lua_init);
>  -	    free(_lua_init);
> -+	    free(_lua_init); _lua_init = NULL;
> ++	    if (_lua_init) free(_lua_init); _lua_init = NULL;
man 3 free
free() frees the memory space pointed to by ptr, which must have been returned 
by a previous call to malloc(), calloc() or realloc().   Otherwise, or if 
free(ptr) has already been called before, undefined behaviour occurs. 
If ptr is NULL, no operation is performed.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

IMO construction like `if(foo) free(foo);' has little value (maybe is useful 
for performance reasons - conditional instruction vs. calling function - I 
don't know). I didn't write any piece of C code for ages, but it seems to me 
that you would like achieve rather sth like:
if(_lua_init) { free(_lua_init); _lua_init = NULL; }


>   	}
>       }
>   #undef	_LUADOTDIR
> ================================================================
>
> ---- CVS-web:
>    
> http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/rpm-lualeak.patch?r1=1.
>1.2.1&r2=1.1.2.2&f=u
>
> _______________________________________________
> pld-cvs-commit mailing list
> pld-cvs-commit at lists.pld-linux.org
> http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit



-- 
Tomasz Wittner


More information about the pld-devel-en mailing list