回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页
[作者 高健@博客园 luckyjackgao@gmail.com]
情形D extract_string_tokens 调用 malloc
==27927== 24,630 (24,576 direct, 54 indirect) bytes in 3 blocks are definitely lost in loss record 100 of 100
==27927== at 0x4A05E1C: malloc (vg_replace_malloc.c:195)
==27927== by 0x40C8FC: extract_string_tokens (pool_config.l:2191)
==27927== by 0x41177B: pool_get_config (pool_config.l:1657)
==27927== by 0x4066B5: main (main.c:320)
main->pool_get_config -> extract_string_tokens -> malloc
int pool_get_config(char *confpath, POOL_CONFIG_CONTEXT context)
bool log_destination_changed = false;
pool_error("pool_config: parse error at line %d '%s'", Lineno, yytext)
fd = fopen(confpath, "r");
fprintf(stderr, "pool_config: could not open configuration file (%s)\n",
fprintf(stderr, "pool_config: using default values...\n");
if (token == POOL_PARSE_ERROR)
if (!strcmp(key, "allow_inet_domain_socket") &&
CHECK_CONTEXT(INIT_CONFIG, context))
else if (!strcmp(key, "reset_query_list") &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
if (token != POOL_STRING && token != POOL_UNQUOTED_STRING &&
str = extract_string(yytext, token);
pool_config->reset_query_list = extract_string_tokens(str, ";", pool_config->num_reset_queries);
if (pool_config->reset_query_list == NULL)
else if (!strcmp(key, "white_function_list") &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
if (token != POOL_STRING && token != POOL_UNQUOTED_STRING &&
str = extract_string(yytext, token);
pool_config->white_function_list =
extract_string_tokens(str, ",",
&pool_config->num_white_function_list);
if (pool_config->white_function_list == NULL)
for (i=0;i<pool_config->num_white_function_list;i++)
add_regex_pattern("white_function_list",
pool_config->white_function_list[i]);
else if (!strcmp(key, "black_function_list") &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context))
if (token != POOL_STRING && token != POOL_UNQUOTED_STRING &&
str = extract_string(yytext, token);
pool_config->black_function_list =
extract_string_tokens(str, ",",
&pool_config->num_black_function_list);
if (pool_config->black_function_list == NULL)
for (i=0;i<pool_config->num_black_function_list;i++)
add_regex_pattern("black_function_list",
pool_config->black_function_list[i]);
else if (!strncmp(key, "backend_flag", 12) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
/* this parameter must be modified by parent pid */
flags = extract_string_tokens(str, "|", &n);
pool_debug("pool_config: unable to get backend flags");
if (!strcmp(flags[i], "ALLOW_TO_FAILOVER"))
if (disallow_to_failover_is_specified)
pool_error("pool_config: cannot set ALLOW_TO_FAILOVER
and DISALLOW_TO_FAILOVER at the same time");
allow_to_failover_is_specified = true;
pool_debug("pool_config: allow_to_failover on");
else if (!strcmp(flags[i], "DISALLOW_TO_FAILOVER"))
if (allow_to_failover_is_specified)
pool_error("pool_config: cannot set ALLOW_TO_FAILOVER
and DISALLOW_TO_FAILOVER at the same time");
disallow_to_failover_is_specified = true;
pool_debug("pool_config: disallow_to_failover on");
pool_error("pool_config: invalid backend flag:%s", flags[i]);
extract_string_tokens 函数:
* Extract tokens separated by delimi from str. Return value is an
* array of pointers to malloced strings. number of tokens is set to
* n; note that str will be destroyed by strtok().
static char **extract_string_tokens(char *str, char *delimi, int *n)
tokens = malloc(MAXTOKENS*sizeof(char *));
pool_error("extract_string_tokens: out of memory");
for (token = strtok(str, delimi); token != NULL && *n < MAXTOKENS; token = strtok(NULL, delimi))
tokens[*n] = strdup(token);
pool_error("extract_string_tokens: out of memory");
pool_debug("extract_string_tokens: token: %s", tokens[*n]);
和情形 A 有些类似,在 extract_string_tokens函数中,调用了 malloc开了内存
由于其 是在 pool_config.c 的 pool_get_config 中被调用,
这个函数 是要实现 把配置文件中的各项内容读取出来。
配置文件项内容的地址,就存储在 返回的 指针里面。
在pgpool 运行结束以前, 都是需要能随时访问 配置文件向内容的。
所以,在pgpool运行结束以前,都是不能随意 释放 。
至于运行结束的那一刻 是否 有代码专门来释放了,前面我们的分析已经说过,不在我们的讨论范围内。
其实,如果略作展开,看pgpool运行结束的时候,是否有可能释放的问题:
flags = extract_string_tokens(str, "|", &n);
pool_get_config 函数,pool_get_config函数中调用 extract_string_tokens ,
此后, 根本无从 保存 flags 指针。所以这段内存,在pgpool运行结束后,只能说是 “丢了"。
[作者 高健@博客园 luckyjackgao@gmail.com]
回到上一级页面: PostgreSQL集群方案相关索引页 回到顶级页面:PostgreSQL索引页
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/08/21/2649124.html,如需转载请自行联系原作者