Skip to content

Commit c49e287

Browse files
committed
Fix memory leak when initializing DH parameters in backend
When loading DH parameters used for the generation of ephemeral DH keys in the backend, the code has never bothered releasing the memory used for the DH information loaded from a file or from libpq's default. This commit makes sure that the information is properly free()'d. Back-patch of e0e569e. We originally thought the leak was minor and not worth back-patching, but Jelte Fennema pointed out that repeated SIGHUP's can result in very serious bloat of the postmaster, which is then multiplied by being duplicated into eadh forked child. Back-patch to v10; the code looked different before c0a15e0, and didn't have a leak in the actually-live code paths. Michael Paquier Discussion: https://postgr.es/m/16160-18367e56e9a28264@postgresql.org
1 parent 20f11ca commit c49e287

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/backend/libpq/be-secure-openssl.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,11 @@ initialize_dh(SSL_CTX *context, bool isServerStart)
993993
(errcode(ERRCODE_CONFIG_FILE_ERROR),
994994
(errmsg("DH: could not set DH parameters: %s",
995995
SSLerrmessage(ERR_get_error())))));
996+
DH_free(dh);
996997
return false;
997998
}
999+
1000+
DH_free(dh);
9981001
return true;
9991002
}
10001003

0 commit comments

Comments
 (0)