Fix: possible null dereference
[lttng-tools.git] / src / common / fd-tracker / inode.c
index 28825b106c6f2c69051e4de96e5cac26e8af7652..16dd49a6ff2c95230efd1aba28fe2788d11c5722 100644 (file)
@@ -1,18 +1,8 @@
 /*
- * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <common/defaults.h>
@@ -143,6 +133,12 @@ static int lttng_unlinked_file_pool_add_inode(
                }
                pool->unlink_directory_handle = lttng_directory_handle_create(
                                pool->unlink_directory_path);
+               if (!pool->unlink_directory_handle) {
+                       ERR("Failed to create directory handle to unlinked file pool at %s",
+                                       pool->unlink_directory_path);
+                       ret = -1;
+                       goto end;
+               }
        }
 
        ret = lttng_directory_handle_rename(inode->location.directory_handle,
@@ -290,7 +286,19 @@ void lttng_inode_put(struct lttng_inode *inode)
        urcu_ref_put(&inode->ref, lttng_inode_release);
 }
 
-void lttng_inode_get_location(struct lttng_inode *inode,
+struct lttng_directory_handle *lttng_inode_get_location_directory_handle(
+               struct lttng_inode *inode)
+{
+       if (inode->location.directory_handle) {
+               const bool reference_acquired = lttng_directory_handle_get(
+                               inode->location.directory_handle);
+
+               assert(reference_acquired);
+       }
+       return inode->location.directory_handle;
+}
+
+void lttng_inode_borrow_location(struct lttng_inode *inode,
                const struct lttng_directory_handle **out_directory_handle,
                const char **out_path)
 {
@@ -514,6 +522,10 @@ struct lttng_inode *lttng_inode_registry_get_inode(
 
        inode = lttng_inode_create(&id, registry->inodes, unlinked_file_pool,
                        handle, path);
+       if (!inode) {
+               goto end_unlock;
+       }
+
        node = cds_lfht_add_unique(registry->inodes,
                        lttng_inode_id_hash(&inode->id), lttng_inode_match,
                        &inode->id, &inode->registry_node);
This page took 0.023399 seconds and 4 git commands to generate.