crypto: fix memory leak in randomBytes() error path

This is the conceptual back-port of commit ec54873 from the master
branch.