From 04e1926df66e20bcae2cc7d0233449b982a04d20 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Wed, 12 Nov 2008 16:10:58 +0000 Subject: Handle malloc() failures during setup of driver-ti --- driver-ti.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/driver-ti.c b/driver-ti.c index 7c5a6f0..f65f474 100644 --- a/driver-ti.c +++ b/driver-ti.c @@ -24,7 +24,7 @@ typedef struct { } termkey_ti; static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmask, int *modsetp); -static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset); +static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset); static void *new_driver(termkey_t *tk, const char *term) { @@ -66,11 +66,15 @@ static void *new_driver(termkey_t *tk, const char *term) continue; if(sym != TERMKEY_SYM_NONE) - register_seq(ti, value, type, sym, mask, set); + if(!register_seq(ti, value, type, sym, mask, set)) + goto abort_free_seqs; } return ti; +abort_free_seqs: + free(ti->seqs); + abort_free_ti: free(ti); @@ -240,12 +244,13 @@ static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_ke return 0; } -static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset) +static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset) { if(ti->nseqs == ti->alloced_seqs) { ti->alloced_seqs *= 2; void *newseqs = realloc(ti->seqs, ti->alloced_seqs * sizeof(ti->seqs[9])); - // TODO: Handle realloc() failure + if(!newseqs) + return 0; ti->seqs = newseqs; } @@ -256,6 +261,8 @@ static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, ter ti->seqs[i].key.sym = sym; ti->seqs[i].key.modifier_mask = modmask; ti->seqs[i].key.modifier_set = modset; + + return 1; } struct termkey_driver termkey_driver_ti = { -- cgit v1.2.3-70-g09d2