Fix most of high impact errors found by Coverity.
Fix incorrect logic in erealloc() that caused an abort when reallocated pointer returned NULL after calling realloc() with size=0.
Sync toolkit.