Fix another function val reference counting bug.

Now that functions get unref'd in the val dtor in order to free mem of
unserialized functions, it's important to ref a function when creating a
val from a pre-existing function so it's not prematurely free'd.
Merge remote-tracking branch 'origin/master' into topic/dnthayer/compilerwarn