Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKPORT 2024.1][#22262] YSQL: Fix memory leak in pg_constraint/pg_a…
…ttrdef local cache Summary: The memory leak was identified via code inspection during debugging the issue. ``` static void YbInitUpdateRelationCacheState(YbUpdateRelationCacheState *state) { YbLoadTupleCache(&state->pg_attrdef_cache, AttrDefaultRelationId, &YbExtractAttrDefTupleCacheKey, "pg_attrdef local cache"); YbLoadTupleCache(&state->pg_constraint_cache, ConstraintRelationId, &YbExtractConstraintTupleCacheKey, "pg_constraint local cache"); } ``` and ``` static void YbLoadTupleCache(YbTupleCache *cache, Oid relid, YbTupleCacheKeyExtractor key_extractor, const char *cache_name) { Assert(!(cache->rel || cache->data)); cache->rel = heap_open(relid, AccessShareLock); HASHCTL ctl = {0}; ctl.keysize = sizeof(Oid); ctl.entrysize = sizeof(YbTupleCacheEntry); cache->data = hash_create(cache_name, 32, &ctl, HASH_ELEM | HASH_BLOBS); ``` We have called `hash_create` in `YbLoadTupleCache`, but in the corresponding `YbCleanupTupleCache` I do not see a call to `hash_destroy`: ``` static void YbCleanupTupleCache(YbTupleCache *cache) { if (!cache->rel) return; heap_close(cache->rel, AccessShareLock); } ``` This diff fixes the memory leak by calling `hash_destroy` in `YbCleanupTupleCache`. Jira: DB-11181 Original commit: 18754b1 / D34845 Test Plan: Manual test. (1) ./bin/yb-ctl create --rf 1 --tserver_flags ysql_catalog_preload_additional_tables=true (2) before the fix ``` yugabyte=# select used_bytes,total_bytes from pg_get_backend_memory_contexts() where name like '%local cache'; used_bytes | total_bytes ------------+------------- 6616 | 8192 5576 | 8192 (2 rows) ``` (3) after the fix ``` yugabyte=# select used_bytes,total_bytes from pg_get_backend_memory_contexts() where name like '%local cache'; used_bytes | total_bytes ------------+------------- (0 rows) ``` Reviewers: kfranz Reviewed By: kfranz Subscribers: yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D35137
- Loading branch information