endtli = backup_state->stoptli;
/* Deallocate backup-related variables. */
- pfree(tablespace_map->data);
- pfree(tablespace_map);
+ destroyStringInfo(tablespace_map);
pfree(backup_state);
}
PG_END_ENSURE_ERROR_CLEANUP(do_pg_abort_backup, BoolGetDatum(false));
appendStringInfoChar(cmd, ')');
res = walrcv_exec(wrconn, cmd->data, 1, tableRow);
- pfree(cmd->data);
- pfree(cmd);
+ destroyStringInfo(cmd);
if (res->status != WALRCV_OK_TUPLES)
ereport(ERROR,
pq_begintypsend(&buf);
pq_sendint8(&buf, version);
pq_sendtext(&buf, jtext->data, jtext->len);
- pfree(jtext->data);
- pfree(jtext);
+ destroyStringInfo(jtext);
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
appendBinaryStringInfo(&xmlerrcxt->err_buf, errorBuf->data,
errorBuf->len);
- pfree(errorBuf->data);
- pfree(errorBuf);
+ destroyStringInfo(errorBuf);
return;
}
(errmsg_internal("%s", errorBuf->data)));
}
- pfree(errorBuf->data);
- pfree(errorBuf);
+ destroyStringInfo(errorBuf);
}
/* Free memory that we don't need any more. */
if (lastbuf != buf)
- {
- pfree(buf->data);
- pfree(buf);
- }
+ destroyStringInfo(buf);
/*
* Return the data from the first backup_info that we read (which is the
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);
+}
* to be len + 1 in size.
*
* To destroy a StringInfo, pfree() the data buffer, and then pfree() the
- * StringInfoData if it was palloc'd. There's no special support for this.
+ * StringInfoData if it was palloc'd. For StringInfos created with
+ * makeStringInfo(), destroyStringInfo() is provided for this purpose.
* However, if the StringInfo was initialized using initReadOnlyStringInfo()
* then the caller will need to consider if it is safe to pfree the data
* buffer.
*/
extern void enlargeStringInfo(StringInfo str, int needed);
+/*------------------------
+ * destroyStringInfo
+ * Frees a StringInfo and its buffer (opposite of makeStringInfo()).
+ */
+extern void destroyStringInfo(StringInfo str);
+
#endif /* STRINGINFO_H */
}
/* Clean up */
- pfree(buf->data);
- pfree(buf);
+ destroyStringInfo(buf);
}
/*