Better free() tracking in constructor failure cases

This commit is contained in:
Paul LeoNerd Evans
2008-10-09 23:19:10 +01:00
parent 286532e602
commit 2b08f88f19
3 changed files with 34 additions and 5 deletions

View File

@@ -37,6 +37,8 @@ static void *new_driver(termkey_t *tk, const char *term)
// Excellent - we'll continue
termkey_csi *csi = malloc(sizeof *csi);
if(!csi)
return NULL;
csi->tk = tk;
@@ -51,6 +53,8 @@ static void *new_driver(termkey_t *tk, const char *term)
csi->ncsifuncs = 32;
csi->csifuncs = malloc(sizeof(csi->csifuncs[0]) * csi->ncsifuncs);
if(!csi->csifuncs)
goto abort_free_csi;
for(i = 0; i < csi->ncsifuncs; i++)
csi->csifuncs[i].sym = TERMKEY_SYM_UNKNOWN;
@@ -119,6 +123,11 @@ static void *new_driver(termkey_t *tk, const char *term)
register_csifunc(csi, TERMKEY_TYPE_FUNCTION, 20, 34, NULL);
return csi;
abort_free_csi:
free(csi);
return NULL;
}
static void free_driver(void *private)