Navigation Menu

Skip to content

Commit

Permalink
db_mysql: use generic PKG_MEM_ERROR, SHM_ERROR and SYS_MEM_ERROR help…
Browse files Browse the repository at this point in the history
…er defines
  • Loading branch information
henningw committed Jan 21, 2019
1 parent ab0de38 commit f3fa003
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
14 changes: 8 additions & 6 deletions src/modules/db_mysql/km_dbase.c
Expand Up @@ -170,7 +170,7 @@ int db_mysql_submit_query_async(const db1_con_t* _h, const str* _s)
asize = sizeof(async_task_t) + 2*sizeof(str) + di->url.len + _s->len + 2;
atask = shm_malloc(asize);
if(atask==NULL) {
LM_ERR("no more shared memory to allocate %d\n", asize);
SHM_MEM_ERROR_FMT("size %d\n", asize);
return -1;
}

Expand Down Expand Up @@ -370,7 +370,7 @@ int db_mysql_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows)
/* Allocate a new result structure */
*_r = db_mysql_new_result();
if (*_r == 0) {
LM_ERR("no memory left\n");
LM_ERR("could not allocate new result\n");
return -2;
}

Expand Down Expand Up @@ -430,7 +430,7 @@ int db_mysql_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows)

RES_ROWS(*_r) = (struct db_row*)pkg_malloc(sizeof(db_row_t) * rows);
if (!RES_ROWS(*_r)) {
LM_ERR("no memory left\n");
PKG_MEM_ERROR;
return -5;
}

Expand Down Expand Up @@ -625,7 +625,7 @@ int db_mysql_start_transaction(db1_con_t* _h, db_locking_t _l)
case DB_LOCKING_WRITE:
if ((lock_str.s = pkg_malloc((lock_start_str.len + CON_TABLE(_h)->len + lock_end_str.len) * sizeof(char))) == NULL)
{
LM_ERR("allocating pkg memory\n");
PKG_MEM_ERROR;
goto error;
}

Expand Down Expand Up @@ -896,8 +896,10 @@ int db_mysql_alloc_buffer(void)
}

mysql_sql_buf = (char*)malloc(sql_buffer_size);
if (mysql_sql_buf == NULL)
if (mysql_sql_buf == NULL) {
SYS_MEM_ERROR;
return -1;
else
} else {
return 0;
}
}
4 changes: 2 additions & 2 deletions src/modules/db_mysql/km_my_con.c
Expand Up @@ -64,7 +64,7 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)

ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
if (!ptr) {
LM_ERR("no private memory left\n");
PKG_MEM_ERROR;
return 0;
}

Expand All @@ -74,7 +74,7 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)

ptr->con = (MYSQL*)pkg_malloc(sizeof(MYSQL));
if (!ptr->con) {
LM_ERR("no private memory left\n");
PKG_MEM_ERROR;
goto err;
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/db_mysql/km_res.c
Expand Up @@ -77,7 +77,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r)
for(col = 0; col < RES_COL_N(_r); col++) {
RES_NAMES(_r)[col] = (str*)pkg_malloc(sizeof(str));
if (! RES_NAMES(_r)[col]) {
LM_ERR("no private memory left\n");
PKG_MEM_ERROR;
db_free_columns(_r);
return -4;
}
Expand Down Expand Up @@ -248,6 +248,7 @@ db1_res_t* db_mysql_new_result(void)
return NULL;
RES_PTR(obj) = pkg_malloc(sizeof(struct my_res));
if (!RES_PTR(obj)) {
PKG_MEM_ERROR;
db_free_result(obj);
return NULL;
}
Expand Down
24 changes: 12 additions & 12 deletions src/modules/db_mysql/my_cmd.c
Expand Up @@ -172,7 +172,7 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd)

sql_cmd->s = pkg_malloc(sql_cmd->len + 1);
if (sql_cmd->s == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
p = sql_cmd->s;
Expand Down Expand Up @@ -256,7 +256,7 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd)

sql_cmd->s = pkg_malloc(sql_cmd->len + 1);
if (sql_cmd->s == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
p = sql_cmd->s;
Expand Down Expand Up @@ -323,7 +323,7 @@ static int build_replace_cmd(str* sql_cmd, db_cmd_t* cmd)

sql_cmd->s = pkg_malloc(sql_cmd->len + 1);
if (sql_cmd->s == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
p = sql_cmd->s;
Expand Down Expand Up @@ -380,7 +380,7 @@ static inline int sb_add(struct string_buffer *sb, str *nstr)
new_size = sb->size + (asize / sb->increment + (asize % sb->increment > 0)) * sb->increment;
newp = pkg_malloc(new_size);
if (!newp) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
if (sb->s) {
Expand Down Expand Up @@ -846,7 +846,7 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params

my_params = (MYSQL_BIND*)pkg_malloc(sizeof(MYSQL_BIND) * (count1 + count2));
if (my_params == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
memset(my_params, '\0', sizeof(MYSQL_BIND) * (count1 + count2));
Expand Down Expand Up @@ -914,7 +914,7 @@ static int check_result(db_cmd_t* cmd, struct my_cmd* payload)
fld = mysql_fetch_field_direct(meta, i);
f->name = pkg_malloc(strlen(fld->name)+1);
if (f->name == NULL) {
ERR("mysql: Out of private memory\n");
PKG_MEM_ERROR;
goto error;
}
strcpy(f->name, fld->name);
Expand Down Expand Up @@ -994,7 +994,7 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld)

result = (MYSQL_BIND*)pkg_malloc(sizeof(MYSQL_BIND) * n);
if (result == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return 1;
}
memset(result, '\0', sizeof(MYSQL_BIND) * n);
Expand Down Expand Up @@ -1032,7 +1032,7 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld)
result[i].buffer_type = MYSQL_TYPE_VAR_STRING;
if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE);
if (f->buf.s == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
err = 1;
goto error;
}
Expand All @@ -1045,7 +1045,7 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld)
result[i].buffer_type = MYSQL_TYPE_VAR_STRING;
if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE);
if (f->buf.s == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
err = 1;
goto error;
}
Expand All @@ -1058,7 +1058,7 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld)
result[i].buffer_type = MYSQL_TYPE_BLOB;
if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE);
if (f->buf.s == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
err = 1;
goto error;
}
Expand Down Expand Up @@ -1175,7 +1175,7 @@ int my_cmd(db_cmd_t* cmd)

res = (struct my_cmd*)pkg_malloc(sizeof(struct my_cmd));
if (res == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
goto error;
}
memset(res, '\0', sizeof(struct my_cmd));
Expand Down Expand Up @@ -1208,7 +1208,7 @@ int my_cmd(db_cmd_t* cmd)
case DB_SQL:
res->sql_cmd.s = (char*)pkg_malloc(cmd->table.len);
if (res->sql_cmd.s == NULL) {
ERR("mysql: Out of private memory\n");
PKG_MEM_ERROR;
goto error;
}
memcpy(res->sql_cmd.s,cmd->table.s, cmd->table.len);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/db_mysql/my_con.c
Expand Up @@ -146,15 +146,15 @@ int my_con(db_con_t* con)

ptr = (struct my_con*)pkg_malloc(sizeof(struct my_con));
if (!ptr) {
LOG(L_ERR, "mysql: No memory left\n");
PKG_MEM_ERROR;
goto error;
}
memset(ptr, '\0', sizeof(struct my_con));
if (db_pool_entry_init(&ptr->gen, my_con_free, con->uri) < 0) goto error;

ptr->con = (MYSQL*)pkg_malloc(sizeof(MYSQL));
if (!ptr->con) {
LOG(L_ERR, "mysql: No enough memory\n");
PKG_MEM_ERROR;
goto error;
}
mysql_init(ptr->con);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/db_mysql/my_fld.c
Expand Up @@ -43,7 +43,7 @@ int my_fld(db_fld_t* fld, char* table)

res = (struct my_fld*)pkg_malloc(sizeof(struct my_fld));
if (res == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
memset(res, '\0', sizeof(struct my_fld));
Expand Down
2 changes: 1 addition & 1 deletion src/modules/db_mysql/my_res.c
Expand Up @@ -57,7 +57,7 @@ int my_res(db_res_t* res)

mr = (struct my_res*)pkg_malloc(sizeof(struct my_res));
if (mr == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
return -1;
}
if (db_drv_init(&mr->gen, my_res_free) < 0) goto error;
Expand Down
3 changes: 2 additions & 1 deletion src/modules/db_mysql/my_uri.c
Expand Up @@ -69,6 +69,7 @@ static int dupl_string(char** dst, const char* begin, const char* end)

*dst = pkg_malloc(end - begin + 1);
if ((*dst) == NULL) {
PKG_MEM_ERROR;
return -1;
}

Expand Down Expand Up @@ -256,7 +257,7 @@ int my_uri(db_uri_t* uri)

res = (struct my_uri*)pkg_malloc(sizeof(struct my_uri));
if (res == NULL) {
ERR("mysql: No memory left\n");
PKG_MEM_ERROR;
goto error;
}
memset(res, '\0', sizeof(struct my_uri));
Expand Down

0 comments on commit f3fa003

Please sign in to comment.