mirror of
https://github.com/postgres/postgres.git
synced 2025-10-25 13:17:41 +03:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user