A use-after-free vulnerability in the PostgreSQL plperl procedural language allows an attacker who can create objects to execute arbitrary code with the privileges of the database operating system user. This occurs by re-entering plperl and freeing a prepared query while an outer invocation is still executing it. The issue affects multiple PostgreSQL versions prior to fixed releases.