Fix some code that could potentially dereference a null pointer.
Fix some code that could potentially dereference a null pointer.

Found by the coverity checker.

arm-hpc/papi,arm-hpc/papi,pyrovski/papi,pyrovski/papi,arm-hpc/papi,pyrovski/papi,pyrovski/papi,pyrovski/papi,arm-hpc/papi,pyrovski/papi,pyrovski/papi,arm-hpc/papi,arm-hpc/papi,pyrovski/papi,arm-hpc/papi