Skip to content

Commit 13b8f1f

Browse files
Merge pull request #1129 from vojtechtrefny/master_static-analysis-fixes-2
More static analysis issues fixes
2 parents a54ce02 + 6489761 commit 13b8f1f

File tree

2 files changed

+42
-49
lines changed

2 files changed

+42
-49
lines changed

src/plugins/fs/generic.c

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,9 @@ static gchar* fs_mount (const gchar *device, gchar *fstype, gboolean read_only,
686686
ret = bd_fs_mount (device, mountpoint, fstype, read_only ? "nosuid,nodev,ro" : "nosuid,nodev", NULL, &l_error);
687687
if (!ret) {
688688
g_propagate_prefixed_error (error, l_error, "Failed to mount '%s': ", device);
689-
g_rmdir (mountpoint);
689+
if (g_rmdir (mountpoint) != 0)
690+
bd_utils_log_format (BD_UTILS_LOG_INFO, "Failed to remove temporary mountpoint '%s'",
691+
mountpoint);
690692
g_free (mountpoint);
691693
return NULL;
692694
} else
@@ -703,6 +705,26 @@ static gchar* fs_mount (const gchar *device, gchar *fstype, gboolean read_only,
703705
return mountpoint;
704706
}
705707

708+
static gboolean fs_unmount (const gchar *device, const gchar *mountpoint, const gchar *operation, GError **error) {
709+
gboolean ret = FALSE;
710+
GError *local_error = NULL;
711+
712+
ret = bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error);
713+
if (!ret) {
714+
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_UNMOUNT_FAIL,
715+
"Failed to unmount '%s' after %s it: %s",
716+
device, operation, local_error->message);
717+
g_clear_error (&local_error);
718+
return FALSE;
719+
} else {
720+
if (g_rmdir (mountpoint) != 0)
721+
bd_utils_log_format (BD_UTILS_LOG_INFO, "Failed to remove temporary mountpoint '%s'",
722+
mountpoint);
723+
}
724+
return TRUE;
725+
}
726+
727+
706728
/**
707729
* xfs_resize_device:
708730
* @device: the device the file system of which to resize
@@ -739,22 +761,18 @@ static gboolean xfs_resize_device (const gchar *device, guint64 new_size, const
739761
success = bd_fs_xfs_resize (mountpoint, new_size, extra, error);
740762

741763
if (unmount) {
742-
ret = bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error);
764+
ret = fs_unmount (device, mountpoint, "resizing", &local_error);
743765
if (!ret) {
744766
if (success) {
745767
/* resize was successful but unmount failed */
746-
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_UNMOUNT_FAIL,
747-
"Failed to unmount '%s' after resizing it: %s",
748-
device, local_error->message);
749-
g_clear_error (&local_error);
768+
g_propagate_error (error, local_error);
750769
return FALSE;
751770
} else
752771
/* both resize and unmount were unsuccessful but the error
753772
from the resize is more important so just ignore the
754773
unmount error */
755774
g_clear_error (&local_error);
756-
} else
757-
g_rmdir (mountpoint);
775+
}
758776
}
759777

760778
return success;
@@ -794,22 +812,18 @@ static gboolean nilfs2_resize_device (const gchar *device, guint64 new_size, GEr
794812
success = bd_fs_nilfs2_resize (device, new_size, error);
795813

796814
if (unmount) {
797-
ret = bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error);
815+
ret = fs_unmount (device, mountpoint, "resizing", &local_error);
798816
if (!ret) {
799817
if (success) {
800818
/* resize was successful but unmount failed */
801-
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_UNMOUNT_FAIL,
802-
"Failed to unmount '%s' after resizing it: %s",
803-
device, local_error->message);
804-
g_clear_error (&local_error);
819+
g_propagate_error (error, local_error);
805820
return FALSE;
806821
} else
807822
/* both resize and unmount were unsuccessful but the error
808823
from the resize is more important so just ignore the
809824
unmount error */
810825
g_clear_error (&local_error);
811-
} else
812-
g_rmdir (mountpoint);
826+
}
813827
}
814828

815829
return success;
@@ -829,23 +843,19 @@ static BDFSBtrfsInfo* btrfs_get_info (const gchar *device, GError **error) {
829843
btrfs_info = bd_fs_btrfs_get_info (mountpoint, error);
830844

831845
if (unmount) {
832-
ret = bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error);
846+
ret = fs_unmount (device, mountpoint, "getting info", &local_error);
833847
if (!ret) {
834848
if (btrfs_info) {
835849
/* info was successful but unmount failed */
836-
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_UNMOUNT_FAIL,
837-
"Failed to unmount '%s' after getting info: %s",
838-
device, local_error->message);
839-
g_clear_error (&local_error);
850+
g_propagate_error (error, local_error);
840851
bd_fs_btrfs_info_free (btrfs_info);
841852
return NULL;
842853
} else
843854
/* both info and unmount were unsuccessful but the error
844855
from the info is more important so just ignore the
845856
unmount error */
846857
g_clear_error (&local_error);
847-
} else
848-
g_rmdir (mountpoint);
858+
}
849859
}
850860

851861
return btrfs_info;
@@ -865,22 +875,18 @@ static gboolean btrfs_resize_device (const gchar *device, guint64 new_size, GErr
865875
success = bd_fs_btrfs_resize (mountpoint, new_size, NULL, error);
866876

867877
if (unmount) {
868-
ret = bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error);
878+
ret = fs_unmount (device, mountpoint, "resizing", &local_error);
869879
if (!ret) {
870880
if (success) {
871881
/* resize was successful but unmount failed */
872-
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_UNMOUNT_FAIL,
873-
"Failed to unmount '%s' after resizing it: %s",
874-
device, local_error->message);
875-
g_clear_error (&local_error);
882+
g_propagate_error (error, local_error);
876883
return FALSE;
877884
} else
878885
/* both resize and unmount were unsuccessful but the error
879886
from the resize is more important so just ignore the
880887
unmount error */
881888
g_clear_error (&local_error);
882-
} else
883-
g_rmdir (mountpoint);
889+
}
884890
}
885891

886892
return success;
@@ -900,22 +906,18 @@ static gboolean btrfs_set_label (const gchar *device, const gchar *label, GError
900906
success = bd_fs_btrfs_set_label (mountpoint, label, error);
901907

902908
if (unmount) {
903-
ret = bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error);
909+
ret = fs_unmount (device, mountpoint, "setting label", &local_error);
904910
if (!ret) {
905911
if (success) {
906-
/* resize was successful but unmount failed */
907-
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_UNMOUNT_FAIL,
908-
"Failed to unmount '%s' after setting label: %s",
909-
device, local_error->message);
910-
g_clear_error (&local_error);
912+
/* label was successful but unmount failed */
913+
g_propagate_error (error, local_error);
911914
return FALSE;
912915
} else
913-
/* both set label and unmount were unsuccessful but the error
914-
from the set label is more important so just ignore the
916+
/* both label and unmount were unsuccessful but the error
917+
from the label is more important so just ignore the
915918
unmount error */
916919
g_clear_error (&local_error);
917-
} else
918-
g_rmdir (mountpoint);
920+
}
919921
}
920922

921923
return success;

src/plugins/lvm/lvm-dbus.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ static GVariant* call_lvm_method (const gchar *obj, const gchar *intf, const gch
693693
static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const gchar *method, GVariant *params, GVariant *extra_params, const BDExtraArg **extra_args, gboolean lock_config, GError **error) {
694694
GVariant *ret = NULL;
695695
gchar *obj_path = NULL;
696-
gchar *task_path = NULL;
696+
g_autofree gchar *task_path = NULL;
697697
guint64 log_task_id = 0;
698698
guint64 prog_id = 0;
699699
gdouble progress = 0.0;
@@ -726,7 +726,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
726726
g_free (log_msg);
727727
/* got a valid result, just return */
728728
g_variant_unref (ret);
729-
g_free (task_path);
730729
g_free (obj_path);
731730
bd_utils_report_finished (prog_id, "Completed");
732731
return TRUE;
@@ -740,7 +739,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
740739
method, obj, log_msg);
741740
bd_utils_log_task_status (log_task_id, log_msg);
742741
bd_utils_report_finished (prog_id, log_msg);
743-
g_free (task_path);
744742
g_free (log_msg);
745743
return FALSE;
746744
}
@@ -751,7 +749,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
751749
g_variant_unref (ret);
752750
} else {
753751
bd_utils_log_task_status (log_task_id, "No result, no job started");
754-
g_free (task_path);
755752
bd_utils_report_finished (prog_id, "Completed");
756753
g_variant_unref (ret);
757754
return TRUE;
@@ -808,7 +805,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
808805
method, obj);
809806
bd_utils_report_finished (prog_id, l_error->message);
810807
g_propagate_error (error, l_error);
811-
g_free (task_path);
812808
return FALSE;
813809
} else {
814810
g_variant_get (ret, "o", &obj_path);
@@ -837,7 +833,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
837833
"Got unknown error when running '%s' method on the '%s' object.",
838834
method, obj);
839835
}
840-
g_free (task_path);
841836
g_propagate_error (error, l_error);
842837
return FALSE;
843838
} else
@@ -852,7 +847,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
852847
if (ret)
853848
g_variant_unref (ret);
854849

855-
g_free (task_path);
856850
return TRUE;
857851
}
858852
} else {
@@ -863,9 +857,6 @@ static gboolean call_lvm_method_sync (const gchar *obj, const gchar *intf, const
863857
bd_utils_report_finished (prog_id, "Completed");
864858
return FALSE;
865859
}
866-
g_free (task_path);
867-
868-
return TRUE;
869860
}
870861

871862
static gboolean call_lvm_obj_method_sync (const gchar *obj_id, const gchar *intf, const gchar *method, GVariant *params, GVariant *extra_params, const BDExtraArg **extra_args, gboolean lock_config, GError **error) {

0 commit comments

Comments
 (0)