Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- src/security/security_apparmor.c | 6 ++---- src/security/security_dac.c | 10 +++------ src/security/security_selinux.c | 37 +++++++++++--------------------- src/security/virt-aa-helper.c | 15 +++++-------- 4 files changed, 23 insertions(+), 45 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 82826d193c..9ad218b383 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -452,12 +452,10 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr G_GNUC_UNUSED, if ((profile_name = get_profile_name(def)) == NULL) return rc; - if (VIR_STRDUP(secdef->label, profile_name) < 0) - goto cleanup; + secdef->label = g_strdup(profile_name); /* set imagelabel the same as label (but we won't use it) */ - if (VIR_STRDUP(secdef->imagelabel, profile_name) < 0) - goto err; + secdef->imagelabel = g_strdup(profile_name); if (!secdef->model) secdef->model = g_strdup(SECURITY_APPARMOR_NAME); diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 5d975f5903..4f646bc3b7 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -111,8 +111,7 @@ virSecurityDACChownListAppend(virSecurityDACChownListPtr list, if (VIR_ALLOC(item) < 0) return -1; - if (VIR_STRDUP(tmp, path) < 0) - goto cleanup; + tmp = g_strdup(path); item->path = tmp; item->src = src; @@ -2311,11 +2310,8 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr, return rc; } - if (seclabel->relabel && !seclabel->imagelabel && - VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) { - VIR_FREE(seclabel->label); - return rc; - } + if (seclabel->relabel && !seclabel->imagelabel) + seclabel->imagelabel = g_strdup(seclabel->label); return 0; } diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index c24a63afd6..d80ec01c5d 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -130,8 +130,8 @@ virSecuritySELinuxContextListAppend(virSecuritySELinuxContextListPtr list, if (VIR_ALLOC(item) < 0) return -1; - if (VIR_STRDUP(item->path, path) < 0 || VIR_STRDUP(item->tcon, tcon) < 0) - goto cleanup; + item->path = g_strdup(path); + item->tcon = g_strdup(tcon); item->remember = remember; item->restore = restore; @@ -444,8 +444,7 @@ virSecuritySELinuxMCSGetProcessRange(char **sens, if (!(contextRange = context_range_get(ourContext))) contextRange = "s0"; - if (VIR_STRDUP(*sens, contextRange) < 0) - goto cleanup; + *sens = g_strdup(contextRange); /* Find and blank out the category part (if any) */ tmp = strchr(*sens, ':'); @@ -622,8 +621,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, _("Unable to format SELinux context")); goto cleanup; } - if (VIR_STRDUP(ret, str) < 0) - goto cleanup; + ret = g_strdup(str); VIR_DEBUG("Generated context '%s'", ret); cleanup: freecon(ourSecContext); @@ -740,8 +738,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) *ptr = '\0'; ptr++; if (*ptr != '\0') { - if (VIR_STRDUP(data->alt_domain_context, ptr) < 0) - goto error; + data->alt_domain_context = g_strdup(ptr); ptr = strchrnul(data->alt_domain_context, '\n'); if (ptr && *ptr == '\n') *ptr = '\0'; @@ -761,8 +758,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr) ptr = strchrnul(data->file_context, '\n'); if (ptr && *ptr == '\n') { *ptr = '\0'; - if (VIR_STRDUP(data->content_context, ptr + 1) < 0) - goto error; + data->content_context = g_strdup(ptr + 1); ptr = strchrnul(data->content_context, '\n'); if (ptr && *ptr == '\n') *ptr = '\0'; @@ -868,8 +864,7 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr, virReportSystemError(errno, "%s", _("unable to get selinux context range")); goto cleanup; } - if (VIR_STRDUP(mcs, range) < 0) - goto cleanup; + mcs = g_strdup(range); break; case VIR_DOMAIN_SECLABEL_DYNAMIC: @@ -919,8 +914,7 @@ virSecuritySELinuxGenLabel(virSecurityManagerPtr mgr, &catMax) < 0) goto cleanup; - if (VIR_STRDUP(mcs, sens) < 0) - goto cleanup; + mcs = g_strdup(sens); break; @@ -2214,8 +2208,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityManagerPtr mgr, dev->source.caps.u.storage.block) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) - return -1; + path = g_strdup(dev->source.caps.u.storage.block); } ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel, true); VIR_FREE(path); @@ -2228,8 +2221,7 @@ virSecuritySELinuxSetHostdevCapsLabel(virSecurityManagerPtr mgr, dev->source.caps.u.misc.chardev) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) - return -1; + path = g_strdup(dev->source.caps.u.misc.chardev); } ret = virSecuritySELinuxSetFilecon(mgr, path, secdef->imagelabel, true); VIR_FREE(path); @@ -2449,8 +2441,7 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurityManagerPtr mgr, dev->source.caps.u.storage.block) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) - return -1; + path = g_strdup(dev->source.caps.u.storage.block); } ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true); VIR_FREE(path); @@ -2463,8 +2454,7 @@ virSecuritySELinuxRestoreHostdevCapsLabel(virSecurityManagerPtr mgr, dev->source.caps.u.misc.chardev) < 0) return -1; } else { - if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) - return -1; + path = g_strdup(dev->source.caps.u.misc.chardev); } ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true); VIR_FREE(path); @@ -3335,8 +3325,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr, } range = context_range_get(ctx); if (range) { - if (VIR_STRDUP(mcs, range) < 0) - goto cleanup; + mcs = g_strdup(range); if (!(label = virSecuritySELinuxGenNewContext(data->file_context, mcs, true))) goto cleanup; diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 9157411133..7d7262ca39 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -772,8 +772,7 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi * 3. re-combine the realpath with the remaining suffix * Note: A totally non existent path is used as-is */ - if (VIR_STRDUP_QUIET(pathdir, path) < 0) - goto cleanup; + pathdir = g_strdup(path); while (!virFileExists(pathdir)) { if ((pathtmp = mdir_name(pathdir)) == NULL) goto cleanup; @@ -783,11 +782,9 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi if (strlen(pathdir) == 1) { /* nothing of the path does exist yet */ - if (VIR_STRDUP_QUIET(tmp, path) < 0) - goto cleanup; + tmp = g_strdup(path); } else { - if (VIR_STRDUP_QUIET(pathtmp, path+strlen(pathdir)) < 0) - goto cleanup; + pathtmp = g_strdup(path + strlen(pathdir)); if ((pathreal = realpath(pathdir, NULL)) == NULL) { vah_error(NULL, 0, pathdir); vah_error(NULL, 0, _("could not find realpath")); @@ -797,8 +794,7 @@ vah_add_path(virBufferPtr buf, const char *path, const char *perms, bool recursi goto cleanup; } - if (VIR_STRDUP_QUIET(perms_new, perms) < 0) - goto cleanup; + perms_new = g_strdup(perms); if (strchr(perms_new, 'w') != NULL) { readonly = false; @@ -1367,8 +1363,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv) break; case 'f': case 'F': - if (VIR_STRDUP_QUIET(ctl->newfile, optarg) < 0) - vah_error(ctl, 1, _("could not allocate memory for disk")); + ctl->newfile = g_strdup(optarg); ctl->append = arg == 'F'; break; case 'h': -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list