Summary: | ASTERISK-19991: Memory leak in cel_pgsql | ||
Reporter: | Etienne Lessard (hexanol) | Labels: | |
Date Opened: | 2012-06-13 07:01:58 | Date Closed: | 2012-09-04 21:20:07 |
Priority: | Major | Regression? | |
Status: | Closed/Complete | Components: | CEL/cel_pgsql |
Versions: | 1.8.13.0 | Frequency of Occurrence | Constant |
Related Issues: | |||
Environment: | Attachments: | ( 0) mem_leak_cel_pgsql.patch | |
Description: | There's a memory leak in cel_pgsql that happens every time a CEL is successfully written to postgres. This happens in this piece of code: {code} [...] result = PQexec(conn, ast_str_buffer(sql)); if (PQresultStatus(result) != PGRES_COMMAND_OK) { pgerror = PQresultErrorMessage(result); ast_log(LOG_WARNING, "Failed to insert call detail record into database!\n"); ast_log(LOG_WARNING, "Reason: %s\n", pgerror); ast_log(LOG_WARNING, "Connection may have been lost... attempting to reconnect.\n"); PQreset(conn); if (PQstatus(conn) == CONNECTION_OK) { ast_log(LOG_NOTICE, "Connection reestablished.\n"); connected = 1; PQclear(result); result = PQexec(conn, ast_str_buffer(sql)); if (PQresultStatus(result) != PGRES_COMMAND_OK) { pgerror = PQresultErrorMessage(result); ast_log(LOG_ERROR, "HARD ERROR! Attempted reconnection failed. DROPPING CALL RECORD!\n"); ast_log(LOG_ERROR, "Reason: %s\n", pgerror); } } PQclear(result); goto ast_log_cleanup; } ast_log_cleanup: ast_free(sql); ast_free(sql2); } ast_mutex_unlock(&pgsql_lock); } {code} As you can see, PQclear(result) will not be called when PQresultStatus(result) == PGRES_COMMAND_OK, thus causing a leak. We have patched the module and ran 35 000 calls and the leak that we observed earlier disappeared. | ||
Comments: | By: Matt Jordan (mjordan) 2012-06-13 08:15:32.835-0500 Would you like to provide the patch that fixes this memory leak? If so, please sign the license contributor agreement and attach the patch as a unified diff. If not, that isn't a problem - but sometimes issues are resolved quicker when a patch is provided. Please also note that cel_pgsql is an extended support module [1]; support for extended support modules typically comes from the Asterisk Developer community. [1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+Module+Support+States By: Etienne Lessard (hexanol) 2012-06-13 08:57:47.667-0500 Yes I've just signed a license agreement after opening the issue, so I'm waiting for a response and I'll then attach the patch. By: Etienne Lessard (hexanol) 2012-06-13 11:48:14.175-0500 I've attached the patch. |