mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 02:26:23 +00:00
use ast_*alloc and don't create duplicated error messages.
... as stated in the coding guidelines. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@18722 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -161,10 +161,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
|
|||||||
|
|
||||||
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
|
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
|
||||||
|
|
||||||
fieldnames = malloc(numFields * sizeof(char *));
|
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
|
||||||
if (!fieldnames) {
|
|
||||||
/* If I can't alloc memory at this point, why bother doing anything else? */
|
|
||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
|
||||||
ast_mutex_unlock(&pgsql_lock);
|
ast_mutex_unlock(&pgsql_lock);
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -223,12 +220,8 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
|
|||||||
|
|
||||||
memset(&ra, 0, sizeof(ra));
|
memset(&ra, 0, sizeof(ra));
|
||||||
|
|
||||||
cfg = ast_config_new();
|
if (!(cfg = ast_config_new()))
|
||||||
if (!cfg) {
|
|
||||||
/* If I can't alloc memory at this point, why bother doing anything else? */
|
|
||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
/* Get the first parameter and first value in our list of passed paramater/value pairs */
|
/* Get the first parameter and first value in our list of passed paramater/value pairs */
|
||||||
newparam = va_arg(ap, const char *);
|
newparam = va_arg(ap, const char *);
|
||||||
@@ -314,10 +307,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
|
|||||||
|
|
||||||
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
|
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
|
||||||
|
|
||||||
fieldnames = malloc(numFields * sizeof(char *));
|
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
|
||||||
if (!fieldnames) {
|
|
||||||
/* If I can't alloc memory at this point, why bother doing anything else? */
|
|
||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
|
||||||
ast_mutex_unlock(&pgsql_lock);
|
ast_mutex_unlock(&pgsql_lock);
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -510,10 +500,7 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
|
|||||||
|
|
||||||
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %ld rows.\n", num_rows);
|
ast_log(LOG_DEBUG, "Postgresql RealTime: Found %ld rows.\n", num_rows);
|
||||||
|
|
||||||
fieldnames = malloc(numFields * sizeof(char *));
|
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
|
||||||
if (!fieldnames) {
|
|
||||||
/* If I can't alloc memory at this point, why bother doing anything else? */
|
|
||||||
ast_log(LOG_WARNING, "Out of memory!\n");
|
|
||||||
ast_mutex_unlock(&pgsql_lock);
|
ast_mutex_unlock(&pgsql_lock);
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -751,36 +738,31 @@ static int pgsql_reconnect(const char *database)
|
|||||||
+ strlen(dbuser)
|
+ strlen(dbuser)
|
||||||
+ strlen(dbpass)
|
+ strlen(dbpass)
|
||||||
+ strlen(my_database);
|
+ strlen(my_database);
|
||||||
connInfo = malloc(size);
|
|
||||||
if (!connInfo) {
|
if (!(connInfo = ast_malloc(size)))
|
||||||
ast_log(LOG_WARNING,
|
|
||||||
"Postgresql RealTime: Insufficient memory to allocate Pgsql resource.\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
|
||||||
sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
|
sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
|
||||||
dbhost, dbport, my_database, dbuser, dbpass);
|
dbhost, dbport, my_database, dbuser, dbpass);
|
||||||
ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
|
ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
|
||||||
pgsqlConn = PQconnectdb(connInfo);
|
pgsqlConn = PQconnectdb(connInfo);
|
||||||
ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
|
ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
|
||||||
free(connInfo);
|
free(connInfo);
|
||||||
connInfo = NULL;
|
connInfo = NULL;
|
||||||
ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
|
ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
|
||||||
if (pgsqlConn) {
|
if (pgsqlConn) {
|
||||||
ast_log(LOG_DEBUG,
|
ast_log(LOG_DEBUG, "Postgresql RealTime: Successfully connected to database.\n");
|
||||||
"Postgresql RealTime: Successfully connected to database.\n");
|
connect_time = time(NULL);
|
||||||
connect_time = time(NULL);
|
return 1;
|
||||||
return 1;
|
} else {
|
||||||
} else {
|
ast_log(LOG_ERROR,
|
||||||
ast_log(LOG_ERROR,
|
"Postgresql RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
|
||||||
"Postgresql RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
|
dbname, dbhost);
|
||||||
dbname, dbhost);
|
ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
|
||||||
ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
|
PQresultErrorMessage(NULL));
|
||||||
PQresultErrorMessage(NULL));
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
ast_log(LOG_DEBUG, "Postgresql RealTime: Everything is fine.\n");
|
ast_log(LOG_DEBUG, "Postgresql RealTime: Everything is fine.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user