add a flag 'type of the union' to safely free model->param[i]->element,
if it contain a malloced string
This commit is contained in:
parent
f6cbaea604
commit
800c9711f2
|
|
@ -9,6 +9,8 @@ option trtol=1
|
||||||
tran 100p 20n
|
tran 100p 20n
|
||||||
*plot i(Vs) i(Vs2)
|
*plot i(Vs) i(Vs2)
|
||||||
plot v(in1)
|
plot v(in1)
|
||||||
|
tran 100p 20n
|
||||||
|
plot v(in1)
|
||||||
rusage
|
rusage
|
||||||
.endc
|
.endc
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -328,6 +328,7 @@ typedef struct Mif_Param_Data_s {
|
||||||
Mif_Boolean_t is_null; /* True if no value given on .model card */
|
Mif_Boolean_t is_null; /* True if no value given on .model card */
|
||||||
int size; /* Size of array (1 if scalar) */
|
int size; /* Size of array (1 if scalar) */
|
||||||
Mif_Value_t *element; /* Value of parameter(s) */
|
Mif_Value_t *element; /* Value of parameter(s) */
|
||||||
|
int eltype; /* type of the element */
|
||||||
|
|
||||||
} Mif_Param_Data_t;
|
} Mif_Param_Data_t;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,19 @@ int
|
||||||
MIFmDelete(GENmodel *gen_model)
|
MIFmDelete(GENmodel *gen_model)
|
||||||
{
|
{
|
||||||
MIFmodel *model = (MIFmodel *) gen_model;
|
MIFmodel *model = (MIFmodel *) gen_model;
|
||||||
int i;
|
int i, j;
|
||||||
|
|
||||||
/* Free the model params stuff allocated in MIFget_mod */
|
/* Free the model params stuff allocated in MIFget_mod */
|
||||||
for (i = 0; i < model->num_param; i++) {
|
for (i = 0; i < model->num_param; i++) {
|
||||||
if (model->param[i]->element)
|
/* delete content of union 'element' if it contains a string */
|
||||||
|
if (model->param[i]->element) {
|
||||||
|
if (model->param[i]->eltype == IF_STRING)
|
||||||
|
FREE(model->param[i]->element[0].svalue);
|
||||||
|
else if (model->param[i]->eltype == IF_STRINGVEC)
|
||||||
|
for (j = 0; j < model->param[i]->size; j++)
|
||||||
|
FREE(model->param[i]->element[j].svalue);
|
||||||
FREE(model->param[i]->element);
|
FREE(model->param[i]->element);
|
||||||
|
}
|
||||||
FREE(model->param[i]);
|
FREE(model->param[i]);
|
||||||
}
|
}
|
||||||
FREE(model->param);
|
FREE(model->param);
|
||||||
|
|
|
||||||
|
|
@ -129,14 +129,17 @@ int MIFmParam(
|
||||||
|
|
||||||
case IF_FLAG:
|
case IF_FLAG:
|
||||||
model->param[param_index]->element[0].bvalue = value->iValue;
|
model->param[param_index]->element[0].bvalue = value->iValue;
|
||||||
|
model->param[param_index]->eltype = IF_FLAG;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_INTEGER:
|
case IF_INTEGER:
|
||||||
model->param[param_index]->element[0].ivalue = value->iValue;
|
model->param[param_index]->element[0].ivalue = value->iValue;
|
||||||
|
model->param[param_index]->eltype = IF_INTEGER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_REAL:
|
case IF_REAL:
|
||||||
model->param[param_index]->element[0].rvalue = value->rValue;
|
model->param[param_index]->element[0].rvalue = value->rValue;
|
||||||
|
model->param[param_index]->eltype = IF_REAL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_STRING:
|
case IF_STRING:
|
||||||
|
|
@ -144,6 +147,7 @@ int MIFmParam(
|
||||||
model->param[param_index]->element[0].svalue =
|
model->param[param_index]->element[0].svalue =
|
||||||
TMALLOC(char, 1 + strlen(value->sValue));
|
TMALLOC(char, 1 + strlen(value->sValue));
|
||||||
strcpy(model->param[param_index]->element[0].svalue, value->sValue);
|
strcpy(model->param[param_index]->element[0].svalue, value->sValue);
|
||||||
|
model->param[param_index]->eltype = IF_STRING;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_COMPLEX:
|
case IF_COMPLEX:
|
||||||
|
|
@ -151,6 +155,7 @@ int MIFmParam(
|
||||||
/* so copy the real and imaginary parts explicitly */
|
/* so copy the real and imaginary parts explicitly */
|
||||||
model->param[param_index]->element[0].cvalue.real = value->cValue.real;
|
model->param[param_index]->element[0].cvalue.real = value->cValue.real;
|
||||||
model->param[param_index]->element[0].cvalue.imag = value->cValue.imag;
|
model->param[param_index]->element[0].cvalue.imag = value->cValue.imag;
|
||||||
|
model->param[param_index]->eltype = IF_COMPLEX;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -166,14 +171,17 @@ int MIFmParam(
|
||||||
|
|
||||||
case IF_FLAGVEC:
|
case IF_FLAGVEC:
|
||||||
model->param[param_index]->element[i].bvalue = value->v.vec.iVec[i];
|
model->param[param_index]->element[i].bvalue = value->v.vec.iVec[i];
|
||||||
|
model->param[param_index]->eltype = IF_FLAGVEC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_INTVEC:
|
case IF_INTVEC:
|
||||||
model->param[param_index]->element[i].ivalue = value->v.vec.iVec[i];
|
model->param[param_index]->element[i].ivalue = value->v.vec.iVec[i];
|
||||||
|
model->param[param_index]->eltype = IF_INTVEC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_REALVEC:
|
case IF_REALVEC:
|
||||||
model->param[param_index]->element[i].rvalue = value->v.vec.rVec[i];
|
model->param[param_index]->element[i].rvalue = value->v.vec.rVec[i];
|
||||||
|
model->param[param_index]->eltype = IF_REALVEC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_STRINGVEC:
|
case IF_STRINGVEC:
|
||||||
|
|
@ -181,6 +189,7 @@ int MIFmParam(
|
||||||
model->param[param_index]->element[i].svalue =
|
model->param[param_index]->element[i].svalue =
|
||||||
TMALLOC(char, 1 + strlen(value->v.vec.sVec[i]));
|
TMALLOC(char, 1 + strlen(value->v.vec.sVec[i]));
|
||||||
strcpy(model->param[param_index]->element[i].svalue, value->v.vec.sVec[i]);
|
strcpy(model->param[param_index]->element[i].svalue, value->v.vec.sVec[i]);
|
||||||
|
model->param[param_index]->eltype = IF_STRINGVEC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IF_CPLXVEC:
|
case IF_CPLXVEC:
|
||||||
|
|
@ -188,6 +197,7 @@ int MIFmParam(
|
||||||
/* so copy the real and imaginary parts explicitly */
|
/* so copy the real and imaginary parts explicitly */
|
||||||
model->param[param_index]->element[i].cvalue.real = value->v.vec.cVec[i].real;
|
model->param[param_index]->element[i].cvalue.real = value->v.vec.cVec[i].real;
|
||||||
model->param[param_index]->element[i].cvalue.imag = value->v.vec.cVec[i].imag;
|
model->param[param_index]->element[i].cvalue.imag = value->v.vec.cVec[i].imag;
|
||||||
|
model->param[param_index]->eltype = IF_CPLXVEC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue