check pointer

This commit is contained in:
c9s 2014-06-01 01:38:22 +08:00
parent 4bb3ba9d04
commit fe57cbf54d

View file

@ -92,6 +92,8 @@ edge * r3_node_connectl(node * n, const char * pat, int len, int dupl, node *chi
pat = zstrndup(pat, len); pat = zstrndup(pat, len);
} }
e = r3_edge_create(pat, len, child); e = r3_edge_create(pat, len, child);
if (!e)
return NULL;
r3_node_append_edge(n, e); r3_node_append_edge(n, e);
return e; return e;
} }
@ -439,6 +441,8 @@ route * r3_route_createl(const char * path, int path_len) {
route * r3_tree_insert_routel(node *tree, int method, char *path, int path_len, void *data) { route * r3_tree_insert_routel(node *tree, int method, char *path, int path_len, void *data) {
route *r = r3_route_createl(path, path_len); route *r = r3_route_createl(path, path_len);
if(!r)
return NULL;
r->request_method = method; // ALLOW GET OR POST METHOD r->request_method = method; // ALLOW GET OR POST METHOD
r3_tree_insert_pathl_(tree, path, path_len, r, data); r3_tree_insert_pathl_(tree, path, path_len, r, data);
return r; return r;
@ -502,6 +506,8 @@ node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route
// insert the first one edge, and break at "p" // insert the first one edge, and break at "p"
node * child = r3_tree_create(3); node * child = r3_tree_create(3);
if (!child)
return NULL;
r3_node_connect(n, zstrndup(path, (int)(p - path)), child); r3_node_connect(n, zstrndup(path, (int)(p - path)), child);
// and insert the rest part to the child // and insert the rest part to the child
@ -529,12 +535,16 @@ node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route
node *c1; node *c1;
if (slug_p > path) { if (slug_p > path) {
c1 = r3_tree_create(3); c1 = r3_tree_create(3);
if (!c1)
return NULL;
r3_node_connectl(n, path, slug_p - path, 1, c1); // duplicate r3_node_connectl(n, path, slug_p - path, 1, c1); // duplicate
} else { } else {
c1 = n; c1 = n;
} }
node * c2 = r3_tree_create(3); node * c2 = r3_tree_create(3);
if (!c2)
return NULL;
edge * op_edge = r3_node_connectl(c1, slug_p, slug_len , 1, c2); edge * op_edge = r3_node_connectl(c1, slug_p, slug_len , 1, c2);
op_edge->opcode = opcode; op_edge->opcode = opcode;
@ -555,6 +565,8 @@ node * r3_tree_insert_pathl_(node *tree, char *path, int path_len, route * route
} }
// only one slug // only one slug
node * child = r3_tree_create(3); node * child = r3_tree_create(3);
if (!child)
return NULL;
r3_node_connect(n, zstrndup(path, path_len) , child); r3_node_connect(n, zstrndup(path, path_len) , child);
child->data = data; child->data = data;
child->endpoint++; child->endpoint++;