[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] xenstore: add explicit memory context parameter to get_parent()



commit f304adbd5e1047b36fb64e98ad400fa17084b9cd
Author:     Juergen Gross <jgross@xxxxxxxx>
AuthorDate: Tue Jul 19 13:30:43 2016 +0200
Commit:     Wei Liu <wei.liu2@xxxxxxxxxx>
CommitDate: Tue Jul 19 12:56:58 2016 +0100

    xenstore: add explicit memory context parameter to get_parent()
    
    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>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/xenstore/xenstored_core.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index accca82..0b22670 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -517,12 +517,16 @@ static enum xs_perm_type perm_for_conn(struct connection 
*conn,
        return perms[0].perms & mask;
 }
 
-static char *get_parent(const char *node)
+/*
+ * Get name of node parent.
+ * Temporary memory allocations are done with ctx.
+ */
+static char *get_parent(const void *ctx, const char *node)
 {
        char *slash = strrchr(node + 1, '/');
        if (!slash)
-               return talloc_strdup(node, "/");
-       return talloc_asprintf(node, "%.*s", (int)(slash - node), node);
+               return talloc_strdup(ctx, "/");
+       return talloc_asprintf(ctx, "%.*s", (int)(slash - node), node);
 }
 
 /* What do parents say? */
@@ -531,7 +535,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;
@@ -826,7 +830,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);
@@ -1046,7 +1050,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;
@@ -1083,7 +1087,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;
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.