aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-10-09 23:19:10 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-10-09 23:19:10 +0100
commit2b08f88f19b0270c9db993c940181535c33a71b3 (patch)
treee18ccfa2bd77c894a652ea20192cc778576ca5c2 /termkey.c
parent286532e6021f1a1a90966a8ecf683d9efc5ec55d (diff)
downloadtermo-2b08f88f19b0270c9db993c940181535c33a71b3.tar.gz
termo-2b08f88f19b0270c9db993c940181535c33a71b3.tar.xz
termo-2b08f88f19b0270c9db993c940181535c33a71b3.zip
Better free() tracking in constructor failure cases
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/termkey.c b/termkey.c
index 47c21f3..688953c 100644
--- a/termkey.c
+++ b/termkey.c
@@ -96,10 +96,8 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
tk->flags = flags;
tk->buffer = malloc(buffsize);
- if(!tk->buffer) {
- free(tk);
- return NULL;
- }
+ if(!tk->buffer)
+ goto abort_free_tk;
tk->buffstart = 0;
tk->buffcount = 0;
@@ -113,6 +111,8 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
tk->nkeynames = 64;
tk->keynames = malloc(sizeof(tk->keynames[0]) * tk->nkeynames);
+ if(!tk->keynames)
+ goto abort_free_buffer;
int i;
for(i = 0; i < tk->nkeynames; i++)
@@ -147,7 +147,7 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
if(!tk->driver_info) {
fprintf(stderr, "Unable to find a terminal driver\n");
- return NULL;
+ goto abort_free_keynames;
}
if(!(flags & TERMKEY_FLAG_NOTERMIOS)) {
@@ -164,6 +164,17 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
}
return tk;
+
+abort_free_keynames:
+ free(tk->keynames);
+
+abort_free_buffer:
+ free(tk->buffer);
+
+abort_free_tk:
+ free(tk);
+
+ return NULL;
}
termkey_t *termkey_new(int fd, int flags)