---
title: "Memory Safety"
description: "1 posts about Memory Safety, summarised, each linking to the original."
---

# Memory Safety
> 1 posts about Memory Safety, summarised, each linking to the original.

## Articles

### [Memory safety for Postgres extensions in C/C++](https://yomu.fyi/post/memory-safety-for-postgres-extensions-in-c-c.md)
- Company: [Clickhouse](https://yomu.fyi/company/clickhouse.md)
- Published: Sep 30, 2026
- Type: Problem & solution

Postgres MemoryContext allocation combined with setjmp/longjmp error handling bypasses C++ destructors, leading to undefined behavior when C++ code runs inside a Postgres extension. C++ exceptions also bypass PG\_CATCH, and an uncaught exception in a background worker aborts the process, forcing the postmaster to restart everything due to potential shared memory corruption. ClickHouse’s four Postgres extensions each used a different approach: pg\_clickhouse replaced clickhouse-cpp with a new C library, pg\_re2 scoped C++ to a single file, pg\_chdb isolated libchdb in a helper executable, and pg\_stat\_ch uses a terminate handler. pg\_chdb’s helper process runs outside the Postgres backend, so a libchdb crash fails only the calling operation without triggering cluster crash recovery. A long-term plan for pg\_stat\_ch moves its C++ dependencies into a helper executable, with PR #129 as the first step to isolate C++ from Postgres code.
