Skip to content

Commit 249b3d8

Browse files
committed
* Replace C-style array with std::array in PgSQL_Connection
* Nulling startup_parameters[i] in ~PgSQL_Connection after freeing
1 parent 50243ef commit 249b3d8

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

include/PgSQL_Connection.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class PgSQL_Conn_Param {
216216

217217
class PgSQL_Variable {
218218
public:
219-
char *value = (char*)"";
219+
char *value = nullptr;
220220
void fill_server_internal_session(nlohmann::json &j, int conn_num, int idx);
221221
void fill_client_internal_session(nlohmann::json &j, int idx);
222222
};
@@ -244,7 +244,7 @@ class PgSQL_Connection_userinfo {
244244

245245
class PgSQL_Connection {
246246
public:
247-
PgSQL_Connection(bool is_client_conn);
247+
explicit PgSQL_Connection(bool is_client_conn);
248248
~PgSQL_Connection();
249249

250250
PG_ASYNC_ST handler(short event);
@@ -500,15 +500,15 @@ class PgSQL_Connection {
500500
unsigned long long pgconnpoll_put;
501501
} statuses;
502502

503-
PgSQL_Variable variables[PGSQL_NAME_LAST_HIGH_WM];
504-
uint32_t var_hash[PGSQL_NAME_LAST_HIGH_WM];
503+
std::array<PgSQL_Variable, PGSQL_NAME_LAST_HIGH_WM> variables = {};
504+
std::array<uint32_t, PGSQL_NAME_LAST_HIGH_WM> var_hash = {};
505505
// for now we store possibly missing variables in the lower range
506506
// we may need to fix that, but this will cost performance
507-
bool var_absent[PGSQL_NAME_LAST_HIGH_WM] = { false };
507+
std::array<bool, PGSQL_NAME_LAST_HIGH_WM> var_absent = {};
508508
std::vector<uint32_t> dynamic_variables_idx;
509509

510-
uint32_t startup_parameters_hash[PGSQL_NAME_LAST_HIGH_WM] = {};
511-
char* startup_parameters[PGSQL_NAME_LAST_HIGH_WM] = {};
510+
std::array<uint32_t, PGSQL_NAME_LAST_HIGH_WM> startup_parameters_hash = {};
511+
std::array<char*, PGSQL_NAME_LAST_HIGH_WM> startup_parameters = {};
512512

513513
/**
514514
* @brief Keeps tracks of the 'server_status'. Do not confuse with the 'server_status' from the

lib/PgSQL_Connection.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ PgSQL_Connection::PgSQL_Connection(bool is_client_conn) {
180180
options.init_connect_sent = false;
181181
userinfo = new PgSQL_Connection_userinfo();
182182

183-
for (int i = 0; i < PGSQL_NAME_LAST_HIGH_WM; i++) {
184-
variables[i].value = NULL;
185-
var_hash[i] = 0;
186-
}
183+
//for (int i = 0; i < PGSQL_NAME_LAST_HIGH_WM; i++) {
184+
// variables[i].value = NULL;
185+
// var_hash[i] = 0;
186+
//}
187187

188188
new_result = true;
189189
is_copy_out = false;
@@ -239,6 +239,7 @@ PgSQL_Connection::~PgSQL_Connection() {
239239
for (int i = 0; i < PGSQL_NAME_LAST_HIGH_WM; ++i) {
240240
if (startup_parameters[i]) {
241241
free(startup_parameters[i]);
242+
startup_parameters[i] = nullptr;
242243
startup_parameters_hash[i] = 0;
243244
}
244245
}

0 commit comments

Comments
 (0)