]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc/storage/zfs: ignore false-positive use-after-free warning
authorAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Wed, 26 Jun 2024 17:28:03 +0000 (19:28 +0200)
committerAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Wed, 26 Jun 2024 17:56:16 +0000 (19:56 +0200)
free(dataset) is perfecly valid after failed realloc(dataset, len) call.

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
src/lxc/storage/zfs.c

index 0047440447bfa173777a90fa3261cf9dd694d624..521a9fd63764ae68117a666e19523489db5b9bca 100644 (file)
@@ -500,12 +500,20 @@ int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
         */
        dataset_len = strlen(dataset);
        len = 4 + dataset_len + 1 + strlen(cname) + 1;
+
+/* see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104069 */
+#pragma GCC diagnostic push
+#if defined __GNUC__ && __GNUC__ >= 12
+#pragma GCC diagnostic ignored "-Wuse-after-free"
+#endif
        new->src = realloc(dataset, len);
        if (!new->src) {
                ERROR("Failed to reallocate memory");
                free(dataset);
                return -1;
        }
+#pragma GCC diagnostic pop
+
        memmove(new->src + 4, new->src, dataset_len);
        memmove(new->src, "zfs:", 4);