Initialise ctx to NULL to avoid uninitialized free, noticed by