gfx: Fixed bunch of NULL references

My C skills are a bit rusty, fixed a bunch of issues with NULL pointers.