mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 03:08:45 +00:00
Merge "cdr_pgsql, cel_pgsql: Store maximum buffer size to prevent reallocation"
This commit is contained in:
@@ -75,6 +75,7 @@ static char *encoding;
|
|||||||
static char *tz;
|
static char *tz;
|
||||||
|
|
||||||
static int connected = 0;
|
static int connected = 0;
|
||||||
|
/* Optimization to reduce number of memory allocations */
|
||||||
static int maxsize = 512, maxsize2 = 512;
|
static int maxsize = 512, maxsize2 = 512;
|
||||||
static time_t connect_time = 0;
|
static time_t connect_time = 0;
|
||||||
static int totalrecords = 0;
|
static int totalrecords = 0;
|
||||||
@@ -453,6 +454,15 @@ static int pgsql_log(struct ast_cdr *cdr)
|
|||||||
records++;
|
records++;
|
||||||
}
|
}
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
|
|
||||||
|
/* Next time, just allocate buffers that are that big to start with. */
|
||||||
|
if (ast_str_strlen(sql) > maxsize) {
|
||||||
|
maxsize = ast_str_strlen(sql);
|
||||||
|
}
|
||||||
|
if (ast_str_strlen(sql2) > maxsize2) {
|
||||||
|
maxsize2 = ast_str_strlen(sql2);
|
||||||
|
}
|
||||||
|
|
||||||
ast_free(sql);
|
ast_free(sql);
|
||||||
ast_free(sql2);
|
ast_free(sql2);
|
||||||
}
|
}
|
||||||
|
@@ -74,6 +74,7 @@ static char *table;
|
|||||||
static char *schema;
|
static char *schema;
|
||||||
|
|
||||||
static int connected = 0;
|
static int connected = 0;
|
||||||
|
/* Optimization to reduce number of memory allocations */
|
||||||
static int maxsize = 512, maxsize2 = 512;
|
static int maxsize = 512, maxsize2 = 512;
|
||||||
static int usegmtime = 0;
|
static int usegmtime = 0;
|
||||||
|
|
||||||
@@ -375,6 +376,14 @@ static void pgsql_log(struct ast_event *event)
|
|||||||
}
|
}
|
||||||
PQclear(result);
|
PQclear(result);
|
||||||
|
|
||||||
|
/* Next time, just allocate buffers that are that big to start with. */
|
||||||
|
if (ast_str_strlen(sql) > maxsize) {
|
||||||
|
maxsize = ast_str_strlen(sql);
|
||||||
|
}
|
||||||
|
if (ast_str_strlen(sql2) > maxsize2) {
|
||||||
|
maxsize2 = ast_str_strlen(sql2);
|
||||||
|
}
|
||||||
|
|
||||||
ast_log_cleanup:
|
ast_log_cleanup:
|
||||||
ast_free(sql);
|
ast_free(sql);
|
||||||
ast_free(sql2);
|
ast_free(sql2);
|
||||||
|
Reference in New Issue
Block a user