diff --git a/src/common/logging.c b/src/common/logging.c
index c78ae793b8..982888eddb 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -78,11 +78,20 @@ pg_logging_init(const char *argv0)
 						value = e + 1;
 
 						if (strcmp(name, "error") == 0)
+						{
+							free(sgr_error);
 							sgr_error = strdup(value);
+						}
 						if (strcmp(name, "warning") == 0)
+						{
+							free(sgr_warning);
 							sgr_warning = strdup(value);
+						}
 						if (strcmp(name, "locus") == 0)
+						{
+							free(sgr_locus);
 							sgr_locus = strdup(value);
+						}
 					}
 				}