The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/329

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
From 1e5d03fed00c80cc644406bf41f71437fcbeb0d0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brau...@ubuntu.com>
Date: Wed, 26 Feb 2020 16:24:44 +0100
Subject: [PATCH] bindings: initialize safely

Signed-off-by: Christian Brauner <christian.brau...@ubuntu.com>
---
 bindings.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/bindings.c b/bindings.c
index f5a6415..8a84a5d 100644
--- a/bindings.c
+++ b/bindings.c
@@ -235,7 +235,7 @@ static void prune_initpid_store(void)
 /* Must be called under store_lock */
 static void save_initpid(struct stat *sb, pid_t pid)
 {
-       __do_free struct pidns_init_store *e = NULL;
+       __do_free struct pidns_init_store *entry = NULL;
        __do_close_prot_errno int pidfd = -EBADF;
        char path[LXCFS_PROC_PID_LEN];
        struct lxcfs_opts *opts = fuse_get_context()->private_data;
@@ -252,18 +252,20 @@ static void save_initpid(struct stat *sb, pid_t pid)
        if (stat(path, &st))
                return;
 
-       e = malloc(sizeof(*e));
-       if (!e)
+       entry = malloc(sizeof(*entry));
+       if (entry)
                return;
 
-       e->ino = sb->st_ino;
-       e->initpid = pid;
-       e->ctime = st.st_ctime;
-       ino_hash = HASH(e->ino);
-       e->next = pidns_hash_table[ino_hash];
-       e->lastcheck = time(NULL);
-       e->init_pidfd = move_fd(pidfd);
-       pidns_hash_table[ino_hash] = move_ptr(e);
+       ino_hash = HASH(entry->ino);
+       *entry = (struct pidns_init_store){
+               .ino            = sb->st_ino,
+               .initpid        = pid,
+               .ctime          = st.st_ctime,
+               .next           = pidns_hash_table[ino_hash],
+               .lastcheck      = time(NULL),
+               .init_pidfd     = move_fd(pidfd),
+       };
+       pidns_hash_table[ino_hash] = move_ptr(entry);
 
        lxcfs_debug("Added cache entry %d for pid %d to init pid cache", 
ino_hash, pid);
 }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to