Work on bad accesses and then memory leaks.

Declaring the pointed stuff const fixes a warning.