Subject How to fix bug in xsqlvar?
Author firebirdsql
I have the following code for the nodejs firebird driver that cleans up resources:
void FBResult::clean_sqlda(XSQLDA *sqlda)
{
int i;
XSQLVAR* var;
for(i = 0, var= sqlda->sqlvar; i < sqlda->sqld;i++,var++)
{
switch(var->sqltype & ~1)
{
case SQL_ARRAY:
case SQL_BLOB: delete (ISC_QUAD*) var->sqldata; break;
case SQL_TIMESTAMP: delete (ISC_TIMESTAMP*) var->sqldata; break;
case SQL_TYPE_TIME: delete (ISC_TIME*) var->sqldata; break;
case SQL_TYPE_DATE: delete (ISC_DATE*) var->sqldata; break;
case SQL_TEXT:
case SQL_VARYING: delete var->sqldata; break;
case SQL_SHORT: delete (int16_t *) var->sqldata; break;
case SQL_LONG: delete (int32_t *) var->sqldata; break;
case SQL_INT64: delete (int64_t *) var->sqldata; break;
case SQL_FLOAT: delete (float *) var->sqldata; break;
case SQL_DOUBLE: delete (double *) var->sqldata; break;
default: return;
}
if(var->sqlind != 0) delete var->sqlind;
}
}

The problem is that if I call a stored procedure that returns a domain type, it throws an exception. If I use the actual datatype, it works fine.

Example #1:
CREATE PROCEDURE test
RETURNS ( username username_domain )

Example #2:
CREATE PROCEDURE test
RETURNS (username VARCHAR(25) )

Example #1 causes nodejs to crash. Example #2 works fine.

Commenting out the line case SQL_VARYING: delete var->sqldata; break; fixes the issue but I think it will cause memory leaks.

How do I fix the line so that it will work for domain types as well?