--- libelwix/src/vars.c 2013/08/21 16:04:14 1.4.20.1 +++ libelwix/src/vars.c 2015/06/25 17:53:50 1.8 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: vars.c,v 1.4.20.1 2013/08/21 16:04:14 misho Exp $ +* $Id: vars.c,v 1.8 2015/06/25 17:53:50 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 @@ -123,6 +123,7 @@ vars2buffer(u_char * __restrict buf, int buflen, int b break; case buffer: case string: + case ptr: if (AIT_LEN(val) > buflen - Limit) { elwix_SetErr(EMSGSIZE, "Short buffer buflen=%d " "needed min %d", buflen, Limit + AIT_LEN(val)); @@ -218,7 +219,8 @@ buffer2vars(u_char * __restrict buf, int buflen, int v val->val.net = le64toh(v[i].val.net); break; case data: - /* WARNING:: remap data type to buffer */ + case ptr: + /* WARNING:: remap data and ptr type to buffer! */ val->val_type = buffer; case buffer: case string: @@ -407,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); } @@ -419,29 +435,28 @@ ait_freeVars(array_t ** __restrict vars) * ait_resideVars() - Calculate footprint of resided variables into array * * @vars = Variable array - * return: -1 error or !=-1 bytes for whole array + * return: bytes for whole array */ -ssize_t +size_t ait_resideVars(array_t * __restrict vars) { - ssize_t ret = 0; + size_t ret = 0; register int i; - if (!vars) - return -1; - - ret = array_Size(vars) * sizeof(ait_val_t); - for (i = 0; i < array_Size(vars); i++) - switch (AIT_TYPE(array(vars, i, ait_val_t*))) { - case buffer: - case string: - case data: - case ptr: - ret += AIT_LEN(array(vars, i, ait_val_t*)); - break; - default: - break; - } + if (vars) { + ret = array_Size(vars) * sizeof(ait_val_t); + for (i = 0; i < array_Size(vars); i++) + switch (AIT_TYPE(array(vars, i, ait_val_t*))) { + case buffer: + case string: + case data: + case ptr: + ret += AIT_LEN(array(vars, i, ait_val_t*)); + break; + default: + break; + } + } return ret; }