--- libelwix/src/vars.c 2013/08/22 08:48:08 1.4.20.3 +++ libelwix/src/vars.c 2016/05/14 11:31:38 1.8.4.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: vars.c,v 1.4.20.3 2013/08/22 08:48:08 misho Exp $ +* $Id: vars.c,v 1.8.4.1 2016/05/14 11:31:38 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 +Copyright 2004 - 2015 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -409,11 +409,25 @@ ait_clrVars(array_t * __restrict vars) void ait_freeVars(array_t ** __restrict vars) { + register int i; + ait_val_t *v; + if (!vars || !*vars) return; - ait_clrVars(*vars); - array_Free(*vars); + for (i = 0; i < array_Size(*vars); i++) + if ((v = array(*vars, i, ait_val_t*))) { + /* free memory if isn't zero copy */ + if (!AIT_IN(v)) { + AIT_FREE_VAL(v); + if ((*vars)->arr_data[i]) + e_free((*vars)->arr_data[i]); + } else + AIT_FREE_VAL(v); + (*vars)->arr_data[i] = NULL; + } + (*vars)->arr_last = -1; + array_Destroy(vars); } @@ -780,23 +794,21 @@ ait_sprintfVar(ait_val_t * __restrict v, const char *f { int ret = 0; va_list lst; - char *str = NULL; + char str[STRSIZ] = { [0 ... STRSIZ - 1] = 0 }; if (!v || !fmt) return -1; va_start(lst, fmt); - ret = vasprintf(&str, fmt, lst); + ret = vsnprintf(str, sizeof str - 1, fmt, lst); va_end(lst); - if (str && ret > -1) { + if (ret > -1) { AIT_FREE_VAL(v); AIT_SET_STR(v, str); } else LOGERR; - if (str) - free(str); return ret; }