libpq_dupevents_alloc_r1.patch
text/x-patch
Filename: libpq_dupevents_alloc_r1.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/interfaces/libpq/fe-exec.c | 6 | 15 |
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 113aab0..8e32b18 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -49,7 +49,7 @@ static int static_client_encoding = PG_SQL_ASCII;
static bool static_std_strings = false;
-static PGEvent *dupEvents(PGEvent *events, int count);
+static PGEvent *dupEvents(PGresult *res, PGEvent *events, int count);
static bool PQsendQueryStart(PGconn *conn);
static int PQsendQueryGuts(PGconn *conn,
const char *command,
@@ -186,7 +186,7 @@ PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
/* copy events last; result must be valid if we need to PQclear */
if (conn->nEvents > 0)
{
- result->events = dupEvents(conn->events, conn->nEvents);
+ result->events = dupEvents(result, conn->events, conn->nEvents);
if (!result->events)
{
PQclear(result);
@@ -337,7 +337,7 @@ PQcopyResult(const PGresult *src, int flags)
/* Wants to copy PGEvents? */
if ((flags & PG_COPYRES_EVENTS) && src->nEvents > 0)
{
- dest->events = dupEvents(src->events, src->nEvents);
+ dest->events = dupEvents(dest, dest->events, src->nEvents);
if (!dest->events)
{
PQclear(dest);
@@ -374,7 +374,7 @@ PQcopyResult(const PGresult *src, int flags)
* Also, the resultInitialized flags are all cleared.
*/
static PGEvent *
-dupEvents(PGEvent *events, int count)
+dupEvents(PGresult *res, PGEvent *events, int count)
{
PGEvent *newEvents;
int i;
@@ -382,7 +382,7 @@ dupEvents(PGEvent *events, int count)
if (!events || count <= 0)
return NULL;
- newEvents = (PGEvent *) malloc(count * sizeof(PGEvent));
+ newEvents = (PGEvent *) pqResultAlloc(res, count * sizeof(PGEvent), TRUE);
if (!newEvents)
return NULL;
@@ -392,14 +392,9 @@ dupEvents(PGEvent *events, int count)
newEvents[i].passThrough = events[i].passThrough;
newEvents[i].data = NULL;
newEvents[i].resultInitialized = FALSE;
- newEvents[i].name = strdup(events[i].name);
+ newEvents[i].name = pqResultStrdup(res, events[i].name);
if (!newEvents[i].name)
- {
- while (--i >= 0)
- free(newEvents[i].name);
- free(newEvents);
return NULL;
- }
}
return newEvents;
@@ -661,12 +656,8 @@ PQclear(PGresult *res)
(void) res->events[i].proc(PGEVT_RESULTDESTROY, &evt,
res->events[i].passThrough);
}
- free(res->events[i].name);
}
- if (res->events)
- free(res->events);
-
/* Free all the subsidiary blocks */
while ((block = res->curBlock) != NULL)
{