Version: 1
-Previous: dd9c71ad0ebfe958e1eca5d078a1f44e929b07aa
+Previous: db86ac85de54ebf927c0bd3b15fb88b9f32ffc37
Head: 5de1f5ff6aaca3df63dc3165c63bd37ba24b7723
Applied:
- p: 5de1f5ff6aaca3df63dc3165c63bd37ba24b7723
Unapplied:
malloc-err: 57342da6cab0db5b9b5dd2f5e75284d1500d2132
af_ib: 414c0cd9299eadb9748ce805155e267ba6bff585
+++ /dev/null
-Bottom: 42e4729a57fa30e42770d8787e4b6b02c7bf2204
-Top: b0bae9f13e357fe01c3e0e890cc06e7fe5b01317
-Author: Dotan Barak <dotanb@dev.mellanox.co.il>
-Date: 2011-11-28 12:21:37 -0800
-
-After allocation of dynamic memory blocks, check that the allocation
-succeeded, if it failed handle it gracefully.
-
-Signed-off-by: Dotan Barak <dotanb@dev.mellanox.co.il>
-Reviewed-by: Erez Shitrit <erezsh@mellanox.co.il>
-
-
----
-
-diff --git a/src/parse.c b/src/parse.c
-index d1c820f..9a01afb 100644
---- a/src/parse.c
-+++ b/src/parse.c
-@@ -71,14 +71,15 @@ static char *expand(char *basename, char *args, int *str_cnt, int *str_size)
-
- char **parse(char *args, int *count)
- {
-- char **ptrs;
-+ char **ptrs = NULL;
- char *str_buf, *cpy, *token, *next;
- int cnt = 0, str_size = 0;
- int i;
-
- /* make a copy that strtok can modify */
-- cpy = malloc(strlen(args) + 1);
-- strcpy(cpy, args);
-+ cpy = strdup(args);
-+ if (!cpy)
-+ return NULL;
-
- if (args[0] == '[') {
- cpy[0] = '\0';
-@@ -92,6 +93,9 @@ char **parse(char *args, int *count)
- if (!next) {
- str_size = strlen(token) + 1;
- str_buf = malloc(str_size);
-+ if (!str_buf)
-+ goto out_cpy;
-+
- strcpy(str_buf, token);
- cnt = 1;
- } else {
-@@ -99,6 +103,9 @@ char **parse(char *args, int *count)
- }
-
- ptrs = malloc((sizeof str_buf * (cnt + 1)) + str_size);
-+ if (!ptrs)
-+ goto out_str_buf;
-+
- memcpy(&ptrs[cnt + 1], str_buf, str_size);
-
- ptrs[0] = (char*) &ptrs[cnt + 1];
-@@ -106,10 +113,12 @@ char **parse(char *args, int *count)
- ptrs[i] = index(ptrs[i - 1], 0) + 1;
- ptrs[i] = NULL;
-
-- free(cpy);
-- free(str_buf);
--
- if (count)
- *count = cnt;
-+
-+out_str_buf:
-+ free(str_buf);
-+out_cpy:
-+ free(cpy);
- return ptrs;
- }