Re: BUG #15838: [contrib] vacuumlo: schema variable checked for NULL three times

From: Timur Birsh <taem(at)linukz(dot)org>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #15838: [contrib] vacuumlo: schema variable checked for NULL three times
Date: 2019-06-07 09:29:05
Message-ID: 3855861559899745@sas2-22600713dea1.qloud-c.yandex.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello Heikki,

Thanks for your reply.

Yes, my first intention was to report that 'table' and 'field' should be checked also, but I was not sure.

Regards.

07.06.2019, 15:21, "Heikki Linnakangas" <hlinnaka(at)iki(dot)fi>:
> On 07/06/2019 09:15, PG Bug reporting form wrote:
>>  vacuumlo() has this (starting on line 239):
>>
>>                   if (!schema || !table || !field)
>>                   {
>>                           fprintf(stderr, "%s", PQerrorMessage(conn));
>>                           PQclear(res);
>>                           PQfinish(conn);
>>                           if (schema != NULL)
>>                                   PQfreemem(schema);
>>                           if (schema != NULL)
>>                                   PQfreemem(table);
>>                           if (schema != NULL)
>>                                   PQfreemem(field);
>>                           return -1;
>>                   }
>>
>>  I think this can be replaced with this:
>>
>>                   if (!schema || !table || !field)
>>                   {
>>                           fprintf(stderr, "%s", PQerrorMessage(conn));
>>                           PQclear(res);
>>                           PQfinish(conn);
>>                           if (schema != NULL) {
>>                                   PQfreemem(schema);
>>                                   PQfreemem(table);
>>                                   PQfreemem(field);
>>                           }
>>                           return -1;
>>                   }
>
> Hmm. Currently, if allocating 'schema' fails, but allocating 'table' or
> 'field' succeeds, you leak memory. I'm pretty sure that was intended to be:
>
>          if (!schema || !table || !field)
>          {
>              fprintf(stderr, "%s", PQerrorMessage(conn));
>              PQclear(res);
>              PQfinish(conn);
>              if (schema != NULL)
>                  PQfreemem(schema);
>              if (table != NULL)
>                  PQfreemem(table);
>              if (field != NULL)
>                  PQfreemem(field);
>              return -1;
>          }
>
> I'll go fix it that way, thanks for the report!
>
> - Heikki

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Gabríel Arthúr Pétursson 2019-06-07 13:56:21 GiST index corruption with large tuples
Previous Message Heikki Linnakangas 2019-06-07 09:21:07 Re: BUG #15838: [contrib] vacuumlo: schema variable checked for NULL three times