diff options
author | mattf <mattf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-02-02 16:09:01 +0000 |
---|---|---|
committer | mattf <mattf@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-02-02 16:09:01 +0000 |
commit | ad4ff268920738181477eb89cd099c26d5679fb0 (patch) | |
tree | 74e8d0ef86d9013be0b334846ca41806ea038f74 /res | |
parent | 6b4277a971e6c3f0920010c27b8c329d425d6fe9 (diff) |
Fix for very unlikely memory leak in res_odbc
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@9071 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r-- | res/res_odbc.c | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/res/res_odbc.c b/res/res_odbc.c index 3f255f0d3..f373a9983 100644 --- a/res/res_odbc.c +++ b/res/res_odbc.c @@ -430,39 +430,41 @@ odbc_obj *new_odbc_obj(char *name, char *dsn, char *username, char *password) { static odbc_obj *new; - new = malloc(sizeof(odbc_obj)); - if (!new) - return NULL; - memset(new, 0, sizeof(odbc_obj)); - new->env = SQL_NULL_HANDLE; - - new->name = malloc(strlen(name) + 1); - if (new->name == NULL) - return NULL; - - new->dsn = malloc(strlen(dsn) + 1); - if (new->dsn == NULL) - return NULL; + if (!(new = calloc(1, sizeof(*new))) || + !(new->name = malloc(strlen(name) + 1)) || + !(new->dsn = malloc(strlen(dsn) + 1))) + goto cleanup; if (username) { - new->username = malloc(strlen(username) + 1); - if (new->username == NULL) - return NULL; + if (!(new->username = malloc(strlen(username) + 1))) + goto cleanup; strcpy(new->username, username); } if (password) { - new->password = malloc(strlen(password) + 1); - if (new->password == NULL) - return NULL; + if (!(new->password = malloc(strlen(password) + 1))) + goto cleanup; strcpy(new->password, password); } strcpy(new->name, name); strcpy(new->dsn, dsn); + new->env = SQL_NULL_HANDLE; new->up = 0; ast_mutex_init(&new->lock); return new; + +cleanup: + if (new) { + free(new->name); + free(new->dsn); + free(new->username); + free(new->password); + + free(new); + } + + return NULL; } void destroy_odbc_obj(odbc_obj **obj) |