Skip to content
Snippets Groups Projects
Commit e6daafb8 authored by Rodrigo Ramírez Norambuena's avatar Rodrigo Ramírez Norambuena Committed by Joshua Colp
Browse files

cdr_pgsql, cel_pgsql: Store maximum buffer size to prevent reallocation

The code previously used a fixed size of 512 for the SQL
queries. Depending on the size this may require it to grow.

This change makes it so if the buffer size does grow the size
is stored and next time the buffer will be large enough.

Change-Id: I55385899f1c06dee47e4274c2d21538037b2d895
parent 009b4417
Branches
Tags
No related merge requests found
...@@ -75,6 +75,7 @@ static char *encoding; ...@@ -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) ...@@ -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);
} }
......
...@@ -71,6 +71,7 @@ static char *pgdbport; ...@@ -71,6 +71,7 @@ static char *pgdbport;
static char *table; static char *table;
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;
...@@ -372,6 +373,14 @@ static void pgsql_log(struct ast_event *event) ...@@ -372,6 +373,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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment