Skip to content

Commit fbd0cee

Browse files
Merge pull request #1181 from vojtechtrefny/master_claude-issues-fixes-2
Fixes for various memory leaks and other issues
2 parents 32b3439 + a667339 commit fbd0cee

File tree

14 files changed

+367
-390
lines changed

14 files changed

+367
-390
lines changed

src/lib/blockdev.c.in

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ static gboolean load_plugins (BDPluginSpec **require_plugins, gboolean reload, g
297297
gboolean requested_loaded = TRUE;
298298
GError *error = NULL;
299299
GSequence *config_files = NULL;
300-
GSList *plugins_sonames[BD_PLUGIN_UNDEF] = {NULL, NULL, NULL, NULL, NULL,
301-
NULL, NULL, NULL, NULL, NULL,
302-
NULL, NULL};
300+
GSList *plugins_sonames[BD_PLUGIN_UNDEF] = {0};
303301
BDPlugin plugin_name = BD_PLUGIN_UNDEF;
304302
guint64 required_plugins_mask = 0;
305303

src/plugins/crypto.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ gboolean bd_crypto_is_tech_avail (BDCryptoTech tech, guint64 mode, GError **erro
381381
case BD_CRYPTO_TECH_LUKS:
382382
ret = mode & (BD_CRYPTO_TECH_MODE_CREATE|BD_CRYPTO_TECH_MODE_OPEN_CLOSE|BD_CRYPTO_TECH_MODE_QUERY|
383383
BD_CRYPTO_TECH_MODE_ADD_KEY|BD_CRYPTO_TECH_MODE_REMOVE_KEY|BD_CRYPTO_TECH_MODE_RESIZE|
384-
BD_CRYPTO_TECH_MODE_SUSPEND_RESUME|BD_CRYPTO_TECH_MODE_BACKUP_RESTORE);
384+
BD_CRYPTO_TECH_MODE_SUSPEND_RESUME|BD_CRYPTO_TECH_MODE_BACKUP_RESTORE|BD_CRYPTO_TECH_MODE_MODIFY);
385385
if (ret != mode) {
386386
g_set_error_literal (error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_TECH_UNAVAIL,
387-
"Only 'create', 'open', 'query', 'add-key', 'remove-key', 'resize', 'suspend-resume', 'backup-restore' supported for LUKS");
387+
"Only 'create', 'open', 'query', 'add-key', 'remove-key', 'resize', 'suspend-resume', 'backup-restore', 'modify' supported for LUKS");
388388
return FALSE;
389389
} else
390390
return TRUE;
@@ -1023,11 +1023,31 @@ gboolean _crypto_luks_format (const gchar *device,
10231023
if (min_entropy > 0) {
10241024
dev_random_fd = open ("/dev/random", O_RDONLY);
10251025
if (dev_random_fd >= 0) {
1026-
ioctl (dev_random_fd, RNDGETENTCNT, &current_entropy);
1026+
if (ioctl (dev_random_fd, RNDGETENTCNT, &current_entropy) < 0) {
1027+
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_FORMAT_FAILED,
1028+
"Failed to get random data entropy level: %s",
1029+
strerror_l (errno, c_locale));
1030+
close (dev_random_fd);
1031+
crypt_free (cd);
1032+
g_strfreev (cipher_specs);
1033+
bd_utils_report_finished (progress_id, l_error->message);
1034+
g_propagate_error (error, l_error);
1035+
return FALSE;
1036+
}
10271037
while (current_entropy < min_entropy) {
10281038
bd_utils_report_progress (progress_id, 0, "Waiting for enough random data entropy");
10291039
sleep (1);
1030-
ioctl (dev_random_fd, RNDGETENTCNT, &current_entropy);
1040+
if (ioctl (dev_random_fd, RNDGETENTCNT, &current_entropy) < 0) {
1041+
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_FORMAT_FAILED,
1042+
"Failed to get random data entropy level: %s",
1043+
strerror_l (errno, c_locale));
1044+
close (dev_random_fd);
1045+
crypt_free (cd);
1046+
g_strfreev (cipher_specs);
1047+
bd_utils_report_finished (progress_id, l_error->message);
1048+
g_propagate_error (error, l_error);
1049+
return FALSE;
1050+
}
10311051
}
10321052
close (dev_random_fd);
10331053
} else {
@@ -1422,6 +1442,7 @@ static gboolean _crypto_close (const gchar *device, const gchar *tech_name, GErr
14221442
if (ret != 0) {
14231443
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
14241444
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
1445+
crypt_free (cd);
14251446
bd_utils_report_finished (progress_id, l_error->message);
14261447
g_propagate_error (error, l_error);
14271448
return FALSE;
@@ -1828,6 +1849,7 @@ gboolean bd_crypto_luks_resize (const gchar *luks_device, guint64 size, BDCrypto
18281849
if (ret != 0) {
18291850
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
18301851
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
1852+
crypt_free (cd);
18311853
bd_utils_report_finished (progress_id, l_error->message);
18321854
g_propagate_error (error, l_error);
18331855
return FALSE;
@@ -1937,6 +1959,7 @@ gboolean bd_crypto_luks_suspend (const gchar *luks_device, GError **error) {
19371959
if (ret != 0) {
19381960
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
19391961
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
1962+
crypt_free (cd);
19401963
bd_utils_report_finished (progress_id, l_error->message);
19411964
g_propagate_error (error, l_error);
19421965
return FALSE;
@@ -1986,6 +2009,7 @@ gboolean bd_crypto_luks_resume (const gchar *luks_device, BDCryptoKeyslotContext
19862009
if (ret != 0) {
19872010
g_set_error (&l_error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
19882011
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
2012+
crypt_free (cd);
19892013
bd_utils_report_finished (progress_id, l_error->message);
19902014
g_propagate_error (error, l_error);
19912015
return FALSE;
@@ -2587,6 +2611,7 @@ BDCryptoLUKSInfo* bd_crypto_luks_info (const gchar *device, GError **error) {
25872611
if (ret != 0) {
25882612
g_set_error (error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
25892613
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
2614+
crypt_free (cd);
25902615
return NULL;
25912616
}
25922617

@@ -2742,6 +2767,7 @@ BDCryptoIntegrityInfo* bd_crypto_integrity_info (const gchar *device, GError **e
27422767
if (ret != 0) {
27432768
g_set_error (error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
27442769
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
2770+
crypt_free (cd);
27452771
return NULL;
27462772
}
27472773

@@ -2811,6 +2837,7 @@ BDCryptoLUKSTokenInfo** bd_crypto_luks_token_info (const gchar *device, GError *
28112837
if (ret != 0) {
28122838
g_set_error (error, BD_CRYPTO_ERROR, BD_CRYPTO_ERROR_DEVICE,
28132839
"Failed to initialize device: %s", strerror_l (-ret, c_locale));
2840+
crypt_free (cd);
28142841
return NULL;
28152842
}
28162843

src/plugins/dm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,16 @@ gboolean bd_dm_remove (const gchar *map_name, GError **error) {
176176
gchar* bd_dm_name_from_node (const gchar *dm_node, GError **error) {
177177
gchar *ret = NULL;
178178
gboolean success = FALSE;
179-
g_autofree gchar *sys_path = g_strdup_printf ("/sys/class/block/%s/dm/name", dm_node);
179+
g_autofree gchar *sys_path = NULL;
180180

181181
if (!dm_node || strlen (dm_node) == 0) {
182182
g_set_error_literal (error, BD_DM_ERROR, BD_DM_ERROR_DEVICE_NOEXIST,
183183
"No DM node specified");
184184
return NULL;
185185
}
186186

187+
sys_path = g_strdup_printf ("/sys/class/block/%s/dm/name", dm_node);
188+
187189
if (access (sys_path, R_OK) != 0) {
188190
g_set_error_literal (error, BD_DM_ERROR, BD_DM_ERROR_SYS,
189191
"Failed to access dm node's parameters under /sys");

src/plugins/fs/generic.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,18 @@ static gboolean xfs_resize_device (const gchar *device, guint64 new_size, const
820820
return FALSE;
821821
}
822822

823+
if (xfs_info->block_size == 0) {
824+
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_FAIL,
825+
"Failed to get block size for device '%s'", device);
826+
bd_fs_xfs_info_free (xfs_info);
827+
return FALSE;
828+
}
829+
823830
mountpoint = fs_mount (device, "xfs", FALSE, &unmount, error);
824-
if (!mountpoint)
831+
if (!mountpoint) {
832+
bd_fs_xfs_info_free (xfs_info);
825833
return FALSE;
834+
}
826835

827836
new_size = (new_size + xfs_info->block_size - 1) / xfs_info->block_size;
828837
bd_fs_xfs_info_free (xfs_info);
@@ -857,6 +866,13 @@ static gboolean f2fs_resize_device (const gchar *device, guint64 new_size, GErro
857866
return FALSE;
858867
}
859868

869+
if (info->sector_size == 0) {
870+
g_set_error (error, BD_FS_ERROR, BD_FS_ERROR_FAIL,
871+
"Failed to get sector size for device '%s'", device);
872+
bd_fs_f2fs_info_free (info);
873+
return FALSE;
874+
}
875+
860876
/* round to nearest sector_size multiple */
861877
new_size = (new_size + info->sector_size - 1) / info->sector_size;
862878

src/plugins/fs/mount.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ static gboolean run_as_user (MountFunc func, MountArgs *args, uid_t run_as_uid,
510510
pid = fork ();
511511

512512
if (pid == -1) {
513+
close (pipefd[0]);
514+
close (pipefd[1]);
513515
g_set_error_literal (error, BD_FS_ERROR, BD_FS_ERROR_FAIL,
514516
"Error forking.");
515517
return FALSE;
@@ -694,8 +696,6 @@ gboolean bd_fs_unmount (const gchar *spec, gboolean lazy, gboolean force, const
694696
return ret;
695697
} else
696698
return do_unmount (&args, error);
697-
698-
return TRUE;
699699
}
700700

701701
/**
@@ -777,8 +777,6 @@ gboolean bd_fs_mount (const gchar *device, const gchar *mountpoint, const gchar
777777
return ret;
778778
} else
779779
return do_mount (&args, error);
780-
781-
return TRUE;
782780
}
783781

784782
/**

0 commit comments

Comments
 (0)