added malloc error handling. Kernel heap full now prevents the program from trying to allocate more memory or crash trying to dereference NULL pointer.