diff options
author | Daniel Gustafsson | 2024-03-16 22:18:28 +0000 |
---|---|---|
committer | Daniel Gustafsson | 2024-03-16 22:18:28 +0000 |
commit | b7831865159d5fb6f0d263e6023f0986589fe254 (patch) | |
tree | f6525ed20cab8159e66d39a0fd7e5ca754bf21aa /src/common/stringinfo.c | |
parent | 927332b95e778c0d15a9fbf96e3efeab0d3d937c (diff) |
Add destroyStringInfo function for cleaning up StringInfos
destroyStringInfo() is a counterpart to makeStringInfo(), freeing a
palloc'd StringInfo and its data. This is a convenience function to
align the StringInfo API with the PQExpBuffer API. Originally added
in the OAuth patchset, it was extracted and committed separately in
order to aid upcoming JSON work.
Author: Daniel Gustafsson <daniel@yesql.se>
Author: Jacob Champion <jacob.champion@enterprisedb.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAOYmi+mWdTd6ujtyF7MsvXvk7ToLRVG_tYAcaGbQLvf=N4KrQw@mail.gmail.com
Diffstat (limited to 'src/common/stringinfo.c')
-rw-r--r-- | src/common/stringinfo.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/stringinfo.c b/src/common/stringinfo.c index c61d5c58f30..ec5fc2422d8 100644 --- a/src/common/stringinfo.c +++ b/src/common/stringinfo.c @@ -350,3 +350,19 @@ enlargeStringInfo(StringInfo str, int needed) str->maxlen = newlen; } + +/* + * destroyStringInfo + * + * Frees a StringInfo and its buffer (opposite of makeStringInfo()). + * This must only be called on palloc'd StringInfos. + */ +void +destroyStringInfo(StringInfo str) +{ + /* don't allow destroys of read-only StringInfos */ + Assert(str->maxlen != 0); + + pfree(str->data); + pfree(str); +} |