Re: Missing NULL check after calling ecpg_strdup - Mailing list pgsql-hackers

From Aleksander Alekseev
Subject Re: Missing NULL check after calling ecpg_strdup
Date
Msg-id CAJ7c6TMO9-aRrz80NbWQr-FFbTRTNh7WJkyWm=2NaXrV_y25uw@mail.gmail.com
Whole thread Raw
In response to Re: Missing NULL check after calling ecpg_strdup  (Aleksander Alekseev <aleksander@tigerdata.com>)
List pgsql-hackers
Hi,

> OK, patch 0002 implements this idea with minimal changes to the existing logic.

Here is a slightly modified version:

``
--- a/src/interfaces/ecpg/ecpglib/prepare.c
+++ b/src/interfaces/ecpg/ecpglib/prepare.c
@@ -570,7 +570,7 @@ AddStmtToCache(int lineno,          /* line # of
statement */
        entry = &stmtCacheEntries[entNo];
        entry->lineno = lineno;
        entry->ecpgQuery = ecpg_strdup(ecpgQuery, lineno, &alloc_failed);
-       if (!entry->ecpgQuery)
+       if (alloc_failed)
                return -1;
        entry->connection = connection;
        entry->execs = 0;
```

We know that ecpgQuery can't be NULL because we hash its value above.
Thus ecpg_strdup can fail only if strdup() fails.

Attachment

pgsql-hackers by date:

Previous
From: vignesh C
Date:
Subject: Re: Document slot's restart_lsn can go backward
Next
From: Álvaro Herrera
Date:
Subject: Re: Log prefix missing for subscriber log messages received from publisher