我在nginx中使用pcre,把pcre_free 和pcre_malloc的指针替换为自己需要分内存和释放内存的函数,然后使用pcre_compile对正则表达式进行了编译,编译完以后就反复的使用pcre_exec对字符串进行匹配,
我只需要判断pcre_exec的返回值即可,如果是等于0,说明匹配上了,不等于说明不匹配,
但是我跑了一段时间,怎么发现内存一直上涨呢,难道pcre_exec有内存泄露吗,其中我只调用pcre_compile一次啊???
代码从nginx中抽象出来如下:
302 pcre *re;
303 const char *error;
304 int erroffset;
305 int rc;
306 char pattern[KRK_MAX_HTTP_EXPECTED+1] = {0,};
307
308 memcpy(pattern, hcp->expected, hcp->expected_len);
309
310 re = pcre_compile(pattern, PCRE_CASELESS, &error, &erroffset, NULL);
311 if (re == NULL) {
312 fprintf(stderr,"compile pcre failed\n");
313 return KRK_ERROR;
314 }
315
316 rc = pcre_exec(re, NULL, hrh->header_start,
317 hrh->header_last - hrh->header_start, 0, 0, NULL, 0);
318 if (rc < 0) {
319
320 rc = pcre_exec(re, NULL, hrh->body_start, hrh->body_len, 0, 0, NULL, 0);
321 if (rc < 0) {
322 pcre_free(re);
323 return KRK_ERROR;
324 }
325 }
326
327
328 pcre_free(re);
329 return KRK_OK;