mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 00:04:53 +00:00
Fix a memory leak pointed out by prashant_jois in #asterisk-bugs. PQclear() was
not called on the result structure after doing a PQexec(). Also, fix up some formatting in passing. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@69016 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -67,13 +67,13 @@ static int connected = 0;
|
|||||||
AST_MUTEX_DEFINE_STATIC(pgsql_lock);
|
AST_MUTEX_DEFINE_STATIC(pgsql_lock);
|
||||||
|
|
||||||
static PGconn *conn = NULL;
|
static PGconn *conn = NULL;
|
||||||
static PGresult *result = NULL;
|
|
||||||
|
|
||||||
static int pgsql_log(struct ast_cdr *cdr)
|
static int pgsql_log(struct ast_cdr *cdr)
|
||||||
{
|
{
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
char sqlcmd[2048] = "", timestr[128];
|
char sqlcmd[2048] = "", timestr[128];
|
||||||
char *pgerror;
|
char *pgerror;
|
||||||
|
PGresult *result;
|
||||||
|
|
||||||
ast_mutex_lock(&pgsql_lock);
|
ast_mutex_lock(&pgsql_lock);
|
||||||
|
|
||||||
@@ -153,26 +153,27 @@ static int pgsql_log(struct ast_cdr *cdr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = PQexec(conn, sqlcmd);
|
result = PQexec(conn, sqlcmd);
|
||||||
if ( PQresultStatus(result) != PGRES_COMMAND_OK) {
|
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
||||||
pgerror = PQresultErrorMessage(result);
|
pgerror = PQresultErrorMessage(result);
|
||||||
ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
|
ast_log(LOG_ERROR,"cdr_pgsql: Failed to insert call detail record into database!\n");
|
||||||
ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
|
ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
|
||||||
ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
|
ast_log(LOG_ERROR,"cdr_pgsql: Connection may have been lost... attempting to reconnect.\n");
|
||||||
PQreset(conn);
|
PQreset(conn);
|
||||||
if (PQstatus(conn) == CONNECTION_OK) {
|
if (PQstatus(conn) == CONNECTION_OK) {
|
||||||
ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
|
ast_log(LOG_ERROR, "cdr_pgsql: Connection reestablished.\n");
|
||||||
connected = 1;
|
connected = 1;
|
||||||
result = PQexec(conn, sqlcmd);
|
result = PQexec(conn, sqlcmd);
|
||||||
if ( PQresultStatus(result) != PGRES_COMMAND_OK)
|
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
|
||||||
{
|
|
||||||
pgerror = PQresultErrorMessage(result);
|
pgerror = PQresultErrorMessage(result);
|
||||||
ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR! Attempted reconnection failed. DROPPING CALL RECORD!\n");
|
ast_log(LOG_ERROR,"cdr_pgsql: HARD ERROR! Attempted reconnection failed. DROPPING CALL RECORD!\n");
|
||||||
ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
|
ast_log(LOG_ERROR,"cdr_pgsql: Reason: %s\n", pgerror);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&pgsql_lock);
|
ast_mutex_unlock(&pgsql_lock);
|
||||||
|
PQclear(result);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
PQclear(result);
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&pgsql_lock);
|
ast_mutex_unlock(&pgsql_lock);
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user