Skip to content

Commit

Permalink
lxc/storage/zfs: ignore false-positive use-after-free warning
Browse files Browse the repository at this point in the history
free(dataset) is perfecly valid after failed realloc(dataset, len) call.

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
  • Loading branch information
mihalicyn committed Jun 26, 2024
1 parent f8aff8f commit 06a454a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lxc/storage/zfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 06a454a

Please sign in to comment.