Register atexit hook only once in pg_upgrade.
authorTom Lane
Thu, 28 Jul 2016 15:39:10 +0000 (11:39 -0400)
committerTom Lane
Thu, 28 Jul 2016 15:39:10 +0000 (11:39 -0400)
start_postmaster() registered stop_postmaster_atexit as an atexit(3)
callback each time through, although the obvious intention was to do
so only once per program run.  The extra registrations were harmless,
so long as we didn't exceed ATEXIT_MAX, but still it's a bug.

Artur Zakirov, with bikeshedding by Kyotaro Horiguchi and me

Discussion: <d279e817-02b5-caa6-215f-cfb05dce109a@postgrespro.ru>

contrib/pg_upgrade/server.c

index 3d041efbfd0a6de2d195ddedbcaa5751f65ffdc3..ab91f0062cd1f5f240e315a29491ecd956bdc3a7 100644 (file)
@@ -174,10 +174,11 @@ start_postmaster(ClusterInfo *cluster, bool throw_error)
 {
    char        cmd[MAXPGPATH * 4 + 1000];
    PGconn     *conn;
-   bool        exit_hook_registered = false;
    bool        pg_ctl_return = false;
    char        socket_string[MAXPGPATH + 200];
 
+   static bool exit_hook_registered = false;
+
    if (!exit_hook_registered)
    {
        atexit(stop_postmaster_atexit);