Skip to content

Commit 174963d

Browse files
committed
criu: avoid malloc in prepare_restore_mounts
The code allocates the new string when it can easily be avoided. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent e0b0158 commit 174963d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/libcrun/criu.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -733,15 +733,13 @@ prepare_restore_mounts (runtime_spec_schema_config_schema *def, char *root, libc
733733

734734
/* Check if the mountpoint is on a tmpfs. CRIU restores
735735
* all tmpfs. We do need to recreate directories on a tmpfs. */
736+
size_t dest_len = strlen (dest);
736737
for (j = 0; j < def->mounts_len; j++)
737738
{
738-
cleanup_free char *dest_loop = NULL;
739-
740739
if (def->mounts[j]->type == NULL || strcmp (def->mounts[j]->type, "tmpfs") != 0)
741740
continue;
742-
743-
xasprintf (&dest_loop, "%s/", def->mounts[j]->destination);
744-
if (strncmp (dest, dest_loop, strlen (dest_loop)) == 0)
741+
size_t mount_len = strlen (def->mounts[j]->destination);
742+
if (mount_len < dest_len && dest[mount_len] == '/' && strncmp (dest, def->mounts[j]->destination, mount_len) == 0)
745743
{
746744
/* This is a mountpoint which is on a tmpfs.*/
747745
on_tmpfs = true;

0 commit comments

Comments
 (0)