Optimize duplicate code and fix memory leak in function fetch_remote_table_info() - Mailing list pgsql-hackers

From Yongtao Huang
Subject Optimize duplicate code and fix memory leak in function fetch_remote_table_info()
Date
Msg-id CAOe1Go3fZdwW9UvAtBJCek7YnFa9itPzO102G4mBgVmtY=9o-A@mail.gmail.com
Whole thread Raw
Responses Re: Optimize duplicate code and fix memory leak in function fetch_remote_table_info()
List pgsql-hackers
This patch fixes two things in the function fetch_remote_table_info().

(1) pfree(pub_names.data) to avoid potential memory leaks.
(2) 2 pieces of code can do the same work,

``` C
foreach(lc, MySubscription->publications)
{
    if (foreach_current_index(lc) > 0)
        appendStringInfoString(&pub_names, ", ");
    appendStringInfoString(&pub_names, quote_literal_cstr(strVal(lfirst(lc))));
}
```
and
``` C
foreach_node(String, pubstr, MySubscription->publications)
{
    char       *pubname = strVal(pubstr);

    if (foreach_current_index(pubstr) > 0)
        appendStringInfoString(&pub_names, ", ");

    appendStringInfoString(&pub_names, quote_literal_cstr(pubname));
}
```
I wanna integrate them into one function `make_pubname_list()` to make the code neater.

Thanks for your time.

Regards

Yongtao Huang
Attachment

pgsql-hackers by date:

Previous
From: Abhijit Menon-Sen
Date:
Subject: Re: [PATCH] Exponential backoff for auth_delay
Next
From: Daniel Gustafsson
Date:
Subject: Re: initdb's -c option behaves wrong way?