diff -urN asterisk_res_wrappers/res/res_odbc.c asterisk_fix_leak/res/res_odbc.c --- asterisk_res_wrappers/res/res_odbc.c 2006-01-20 16:53:37.000000000 -0500 +++ asterisk_fix_leak/res/res_odbc.c 2006-01-20 16:52:41.000000000 -0500 @@ -430,34 +430,42 @@ odbc_obj *new_odbc_obj(char *name, char *dsn, char *username, char *password) { static odbc_obj *new; - - if (!(new = ast_calloc(1, sizeof(*new)))) - return NULL; - new->env = SQL_NULL_HANDLE; - - if (!(new->name = ast_malloc(strlen(name) + 1))) - return NULL; - if (!(new->dsn = ast_malloc(strlen(dsn) + 1))) - return NULL; + if (!(new = ast_calloc(1, sizeof(*new))) || + !(new->name = ast_malloc(strlen(name) + 1)) || + !(new->dsn = ast_malloc(strlen(dsn) + 1))) + goto cleanup; if (username) { if (!(new->username = ast_malloc(strlen(username) + 1))) - return NULL; + goto cleanup; strcpy(new->username, username); } if (password) { if (!(new->password = ast_malloc(strlen(password) + 1))) - return NULL; + 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)