You'll want to strdup envvar before calling putenv.
I've strdup()ed the input to putenv and the output of getenv, but it seems to have made little difference.
You'll probably want to call make_shared_string on rv before returning it, too.
According to interpret.h, push_text includes a make_shared_string.
It's really odd, as it doesn't always fail, and it's not obvious that there's any pattern (not that that would make any difference). It does fail about 33 times over 2050 iterations of increasing length.
Example (showing only failures):
# /usr/local/bin/pike test.pike fail: put "BASEAAAA", got "BASEAAA" fail: put "BASEAAAAA", got "BASEAAA" fail: put "BASEAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAAAAAAA", got "BASEAAA" fail: put "BASEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", got "BASEAAAAAAAAAAAAAAAA" fail: put "BASEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", got "BASEAAAAAAAAAAAAAAAAAAAAAAAA"