Various fixes for when malloc fails. Fixed memory leak in environment handling. Fixed the knapsack and sierpinski triangle examples.