!4238 修改gs_ctl内存泄漏问题
Merge pull request !4238 from 申正/fix_gs_ctl_mem_leak
This commit is contained in:
@ -7332,6 +7332,10 @@ static void free_ctl()
|
||||
FREE_AND_RESET(register_password);
|
||||
FREE_AND_RESET(pgha_str);
|
||||
FREE_AND_RESET(pgha_opt);
|
||||
FREE_AND_RESET(exec_path);
|
||||
FREE_AND_RESET(pg_data);
|
||||
FREE_AND_RESET(pg_config);
|
||||
FREE_AND_RESET(pgxcCommand);
|
||||
FREE_AND_RESET(ss_instance_config.dss.vgname);
|
||||
FREE_AND_RESET(ss_instance_config.dss.vgdata);
|
||||
}
|
||||
|
@ -572,9 +572,6 @@ void set_pglocale_pgservice(const char* argv0, const char* app)
|
||||
char path[MAXPGPATH];
|
||||
char my_exec_path[MAXPGPATH];
|
||||
|
||||
/* longer than PGLOCALEDIR */
|
||||
char env_path[MAXPGPATH + sizeof("PGSYSCONFDIR=")];
|
||||
|
||||
/* don't set LC_ALL in the backend */
|
||||
if (strcmp(app, PG_TEXTDOMAIN("gaussdb")) != 0) {
|
||||
(void)gs_setlocale_r(LC_ALL, "");
|
||||
@ -589,40 +586,14 @@ void set_pglocale_pgservice(const char* argv0, const char* app)
|
||||
bindtextdomain(app, path);
|
||||
textdomain(app);
|
||||
|
||||
if (gs_getenv_r("PGLOCALEDIR") == NULL) {
|
||||
char* ptr = NULL;
|
||||
/* set for libpq to use */
|
||||
errno_t rc = snprintf_s(env_path, sizeof(env_path), sizeof(env_path) - 1, "PGLOCALEDIR=%s", path);
|
||||
securec_check_ss_c(rc, "\0", "\0");
|
||||
canonicalize_path(env_path + 12);
|
||||
#ifdef FRONTEND
|
||||
ptr = strdup(env_path);
|
||||
#else
|
||||
ptr = MemoryContextStrdup(THREAD_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR), env_path);
|
||||
#endif
|
||||
if (ptr != NULL) {
|
||||
gs_putenv_r(ptr);
|
||||
}
|
||||
}
|
||||
gs_setnev_r("PGLOCALEDIR", path, 0);
|
||||
#endif
|
||||
|
||||
if (gs_getenv_r("PGSYSCONFDIR") == NULL) {
|
||||
char* ptr = NULL;
|
||||
|
||||
get_etc_path(my_exec_path, path, sizeof(path));
|
||||
|
||||
/* set for libpq to use */
|
||||
errno_t rc = snprintf_s(env_path, sizeof(env_path), sizeof(env_path) - 1, "PGSYSCONFDIR=%s", path);
|
||||
securec_check_ss_c(rc, "\0", "\0");
|
||||
canonicalize_path(env_path + 13);
|
||||
#ifdef FRONTEND
|
||||
ptr = strdup(env_path);
|
||||
#else
|
||||
ptr = MemoryContextStrdup(THREAD_GET_MEM_CXT_GROUP(MEMORY_CONTEXT_EXECUTOR), env_path);
|
||||
#endif
|
||||
if (ptr != NULL) {
|
||||
gs_putenv_r(ptr);
|
||||
}
|
||||
gs_setenv_r("PGSYSCONFDIR", path, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ extern void pgwin32_unsetenv(const char*);
|
||||
|
||||
int gs_putenv_r(char* envvar);
|
||||
char* gs_getenv_r(const char* name);
|
||||
int gs_setenv_r(const char* name, const char* envvar, int overwrite);
|
||||
int gs_unsetenv_r(const char* name);
|
||||
#endif
|
||||
|
||||
@ -50,6 +51,15 @@ char* gs_getenv_r(const char* name)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int gs_setenv_r(const char* name, const char* envvar, int overwrite)
|
||||
{
|
||||
int ret;
|
||||
(void)syscalllockAcquire(&env_lock);
|
||||
ret = setenv(name, envvar, overwrite);
|
||||
(void)syscalllockRelease(&env_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int gs_unsetenv_r(const char* name)
|
||||
{
|
||||
int ret;
|
||||
|
@ -429,6 +429,7 @@ extern struct dirent* gs_readdir(DIR* dir);
|
||||
|
||||
/*env thread safe version*/
|
||||
extern int gs_putenv_r(char* envvar);
|
||||
extern int gs_setenv_r(const char* name, const char* envvar, int overwrite);
|
||||
extern char* gs_getenv_r(const char* name);
|
||||
|
||||
#endif /* PG_PORT_H */
|
||||
|
Reference in New Issue
Block a user