There's a bug in something you're using - there's no way you should be able to cause an invalid free() by writing PHP.
My first suspicions fall pdo_oci extension; after all, it's documented as "Use at your own risk". If you can put together a test case that reliably reproduces it, you'd be best submitting a bug report.
Assuming you don't want to wait around for a fix, you could use the [man]OCI8[/man] extension instead. Obviously it means not using PDO, but your database communication code is all in one place so that it can be swapped with something else, right?
Alternatively: to change the database, close the connection to the current database and open an new one to the other database.