layer insertion - fixing segfault

Imitating what is done when parsing a mapfile in mapserver's code,
instead of using the provided API to insert a layerObj.