Coverity Scan Fixes

Coverity Scan found 16 issues.  This patch fixes 14 of those issues.

the fix for the 15th issue (the dpointer delete in libkode/function.cpp) is commented out because it causes a segfault in the code generator during the build

the 16th issue is a false positive.

all tests still pass, but I did make some educated guesses in a few places to make Coverity happy even though I'm not 100% sure what the code should be doing.