[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH v2 2/5] xenstore: add explicit memory context parameter to get_parent()
On Mon, Jul 18, 2016 at 09:31:26AM +0200, Juergen Gross wrote: > Add a parameter to xenstored get_parent() function to explicitly > specify the memory context to be used for allocations. This will make > it easier to avoid memory leaks by using a context which is freed > soon. > > When available use a temporary context when calling get_parent(), > otherwise mimic the old behavior by calling get_parent() with the same > argument for both parameters. > > Signed-off-by: Juergen Gross <jgross@xxxxxxxx> > --- > tools/xenstore/xenstored_core.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c > index 94c809c..9448ee8 100644 > --- a/tools/xenstore/xenstored_core.c > +++ b/tools/xenstore/xenstored_core.c > @@ -507,12 +507,12 @@ static enum xs_perm_type perm_for_conn(struct > connection *conn, > return perms[0].perms & mask; > } > > -static char *get_parent(const char *node) > +static char *get_parent(const void *mem, const char *node) I would name mem ctx or context instead. And maybe document this function a bit saying that memory allocation is done with the first parameter. With those cosmetic issues fixed: Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx> > { > char *slash = strrchr(node + 1, '/'); > if (!slash) > - return talloc_strdup(node, "/"); > - return talloc_asprintf(node, "%.*s", (int)(slash - node), node); > + return talloc_strdup(mem, "/"); > + return talloc_asprintf(mem, "%.*s", (int)(slash - node), node); > } > > /* What do parents say? */ > @@ -521,7 +521,7 @@ static enum xs_perm_type ask_parents(struct connection > *conn, const char *name) > struct node *node; > > do { > - name = get_parent(name); > + name = get_parent(name, name); > node = read_node(conn, name); > if (node) > break; > @@ -816,7 +816,7 @@ static struct node *construct_node(struct connection > *conn, const char *name) > const char *base; > unsigned int baselen; > struct node *parent, *node; > - char *children, *parentname = get_parent(name); > + char *children, *parentname = get_parent(name, name); > > /* If parent doesn't exist, create it. */ > parent = read_node(conn, parentname); > @@ -1036,7 +1036,7 @@ static int _rm(struct connection *conn, struct node > *node, const char *name) > /* Delete from parent first, then if we crash, the worst that can > happen is the child will continue to take up space, but will > otherwise be unreachable. */ > - struct node *parent = read_node(conn, get_parent(name)); > + struct node *parent = read_node(conn, get_parent(name, name)); > if (!parent) { > send_error(conn, EINVAL); > return 0; > @@ -1073,7 +1073,7 @@ static void do_rm(struct connection *conn, struct > buffered_data *in) > if (!node) { > /* Didn't exist already? Fine, if parent exists. */ > if (errno == ENOENT) { > - node = read_node(conn, get_parent(name)); > + node = read_node(conn, get_parent(in, name)); > if (node) { > send_ack(conn, XS_RM); > return; > -- > 2.6.6 > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |