The system I have used to debug the code is x86 64bit based, Ubuntu 1404 and postgres 9.3.13, I have revised the code and it looks like as following:
Datum vquery(PG_FUNCTION_ARGS) {
int array_len = PG_GETARG_INT32(0);
int64 * node_ids;
ArrayType * retarr;
Datum * vals ;
SPI_connect();
//some code to retrieve data from various tables
// node_ids are allocated and filled up
vals = SPI_palloc(array_len * sizeof(Datum));
memset (vals, 0, array_len * sizeof(Datum));
// fill the vals up
for (i = 0 ; i < array_len ; i++)
vals[i] = Int64GetDatum((node_ids[i]));
retarr = construct_array(vals, retcnt, INT8OID, sizeof(int64), true, 'd');
SPI_finish();
PG_RETURN_ARRAYTYPE_P(retarr);
}