imagecache: fix locking and add missing fclose()
httpc: fix some memory leaks in the error paths