Skip to content

Commit 6908ce7

Browse files
committed
Fix crash in tmpfs_snap_load_cleanup().
XXX rework this; committing for test purposes only.
1 parent 0d575fe commit 6908ce7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

sys/tmpfs/tmpfs_snapshot.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,14 @@ tmpfs_snap_load_file(struct vnode *vp, uint64_t *off, tmpfs_mount_t *tmp,
480480
{
481481
tmpfs_node_t *node = NULL;
482482
uint64_t size;
483-
int error;
483+
int error, allocated = 0;
484484

485485
tmpfs_snap_find_node(tmp, tnhdr->tsn_id, &node);
486486
if (node) {
487487
if (node->tn_type != VREG)
488488
return (EFTYPE);
489489
} else {
490+
allocated = 1;
490491
error = tmpfs_snap_alloc_node(tmp, tnhdr, NULL, NODEV, &node);
491492
if (error)
492493
return (error);
@@ -495,7 +496,14 @@ tmpfs_snap_load_file(struct vnode *vp, uint64_t *off, tmpfs_mount_t *tmp,
495496
if ((size = tnhdr->tsn_spec.tsn_size)) {
496497
if ((error = tmpfs_snap_node_setsize(tmp, node, size)) ||
497498
(error = tmpfs_snap_file_io(vp, UIO_READ, node, off))) {
498-
tmpfs_free_node(tmp, node);
499+
/*
500+
* XXX don't free the node if we haven't allocated it,
501+
* since it might be attached to a directory, and we
502+
* will later step on a free'd node in
503+
* tmpfs_snap_load_cleanup().
504+
*/
505+
if (allocated)
506+
tmpfs_free_node(tmp, node);
499507
return (error);
500508
}
501509
}

0 commit comments

Comments
 (0)