Maybe check fg is NULL or not, before using this pointer.