From nobody Sat May 11 07:55:51 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1710447863410292.7035142960658; Thu, 14 Mar 2024 13:24:23 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F1B551B19; Thu, 14 Mar 2024 16:24:21 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1BC221ABC; Thu, 14 Mar 2024 16:23:30 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A89E1ABB; Thu, 14 Mar 2024 16:23:27 -0400 (EDT) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id DC83C1AB8 for ; Thu, 14 Mar 2024 16:23:23 -0400 (EDT) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-413f1853bf3so7375045e9.0 for ; Thu, 14 Mar 2024 13:23:23 -0700 (PDT) Received: from localhost.localdomain ([212.70.118.236]) by smtp.gmail.com with ESMTPSA id c16-20020a05600c0a5000b00413f7c89c0esm1906472wmq.24.2024.03.14.13.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 13:23:21 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710447802; x=1711052602; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A0/h5hlkcMec+Jg6BPwxzfwEpQO9HBUATbmi/Pkacw0=; b=bXldQropZKJkPOEC5HeJyej46tDkTdAufWEfs4IgO3Y3f6pNuzijg0c39LqIhlgtZK BcmyCrYF96gvVM17D+x6iZRH68JhzU5mbQaP0VijU+DIlOUUdl/cipwX7ALhIzdjjfWD rJjDh+aBNlmued+Wos+mtcjhTtJazOHAMYjWlogclx2A2xj4Xf0mP1eWaD5DSqVDU3Jy ou6Ou2N3iSyXaKKSHtc0LbwzaqXd2cSOvhXB6J2ZJTyH5xu4IjfTt0DcN1+Jk+hiIJV6 hA25kl09KatROiV31szdUAMuAMTSzMw7qyMOB+i8LxeQqucr6w1BSCJKzqHmP0IRNb6g pOGA== X-Gm-Message-State: AOJu0Yywi6w9kumtaDjoheQXkItFtiH1fHYbOMvuKoU2uLU/aQs5FQ/w Mr9i1ITt6EqIXtsc+aafNVax5CGg/k/iTk/O6qWtTdzABCnTrORh3gD577o5ogE= X-Google-Smtp-Source: AGHT+IEx14NgPn3a/DuHAW706aqj4A7Mc9lNidvwuNKGi5gDogMV2BwmBgmoUbv8npPmVCs6XI282Q== X-Received: by 2002:a05:600c:4f50:b0:413:1622:4d04 with SMTP id m16-20020a05600c4f5000b0041316224d04mr2374856wmq.12.1710447801964; Thu, 14 Mar 2024 13:23:21 -0700 (PDT) From: Rayhan Faizel To: devel@lists.libvirt.org Subject: [PATCH v2] openvz_conf: Use g_autofree Date: Fri, 15 Mar 2024 01:52:49 +0530 Message-Id: <20240314202248.1201800-1-rayhan.faizel@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: RJTTT2EYOTWIF4YRHS3KWK4MRX3E2XXR X-Message-ID-Hash: RJTTT2EYOTWIF4YRHS3KWK4MRX3E2XXR X-MailFrom: rayhan.faizel@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Rayhan Faizel X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1710447865464100001 Signed-off-by: Rayhan Faizel Reviewed-by: Michal Privoznik --- src/openvz/openvz_conf.c | 60 ++++++++++++---------------------------- 1 file changed, 17 insertions(+), 43 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index eab3f748d0..4dbaef356c 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -163,7 +163,7 @@ openvzReadNetworkConf(virDomainDef *def, { int ret; virDomainNetDef *net =3D NULL; - char *temp =3D NULL; + g_autofree char *temp =3D NULL; char *token, *saveptr =3D NULL; =20 /*parse routing network configuration* @@ -258,12 +258,9 @@ openvzReadNetworkConf(virDomainDef *def, } } =20 - VIR_FREE(temp); - return 0; =20 error: - VIR_FREE(temp); virDomainNetDefFree(net); return -1; } @@ -276,7 +273,7 @@ openvzReadFSConf(virDomainDef *def, int ret; virDomainFSDef *fs =3D NULL; g_autofree char *veid_str =3D NULL; - char *temp =3D NULL; + g_autofree char *temp =3D NULL; const char *param; unsigned long long barrier, limit; =20 @@ -337,11 +334,8 @@ openvzReadFSConf(virDomainDef *def, =20 VIR_APPEND_ELEMENT(def->fss, def->nfss, fs); =20 - VIR_FREE(temp); - return 0; error: - VIR_FREE(temp); virDomainFSDefFree(fs); return -1; } @@ -351,7 +345,7 @@ static int openvzReadMemConf(virDomainDef *def, int veid) { int ret =3D -1; - char *temp =3D NULL; + g_autofree char *temp =3D NULL; unsigned long long barrier, limit; const char *param; long kb_per_pages; @@ -411,7 +405,6 @@ openvzReadMemConf(virDomainDef *def, int veid) =20 ret =3D 0; error: - VIR_FREE(temp); return ret; } =20 @@ -549,7 +542,7 @@ openvzWriteConfigParam(const char * conf_file, const ch= ar *param, const char *va g_autofree char *temp_file =3D NULL; int temp_fd =3D -1; FILE *fp; - char *line =3D NULL; + g_autofree char *line =3D NULL; size_t line_size =3D 0; =20 temp_file =3D g_strdup_printf("%s.tmp", conf_file); @@ -586,12 +579,9 @@ openvzWriteConfigParam(const char * conf_file, const c= har *param, const char *va if (rename(temp_file, conf_file) < 0) goto error; =20 - VIR_FREE(line); - return 0; =20 error: - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); VIR_FORCE_CLOSE(temp_fd); if (temp_file) @@ -602,14 +592,13 @@ openvzWriteConfigParam(const char * conf_file, const = char *param, const char *va int openvzWriteVPSConfigParam(int vpsid, const char *param, const char *value) { - char *conf_file; + g_autofree char *conf_file =3D NULL; int ret; =20 if (openvzLocateConfFile(vpsid, &conf_file, "conf") < 0) return -1; =20 ret =3D openvzWriteConfigParam(conf_file, param, value); - VIR_FREE(conf_file); return ret; } =20 @@ -622,7 +611,7 @@ openvzWriteVPSConfigParam(int vpsid, const char *param,= const char *value) int openvzReadConfigParam(const char *conf_file, const char *param, char **val= ue) { - char *line =3D NULL; + g_autofree char *line =3D NULL; size_t line_size =3D 0; FILE *fp; int err =3D 0; @@ -652,7 +641,6 @@ openvzReadConfigParam(const char *conf_file, const char= *param, char **value) /* keep going - last entry wins */ } } - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); =20 return err ? -1 : *value ? 1 : 0; @@ -672,21 +660,20 @@ openvzReadConfigParam(const char *conf_file, const ch= ar *param, char **value) int openvzReadVPSConfigParam(int vpsid, const char *param, char **value) { - char *conf_file; + g_autofree char *conf_file =3D NULL; int ret; =20 if (openvzLocateConfFile(vpsid, &conf_file, "conf") < 0) return -1; =20 ret =3D openvzReadConfigParam(conf_file, param, value); - VIR_FREE(conf_file); return ret; } =20 static int openvz_copyfile(char* from_path, char* to_path) { - char *line =3D NULL; + g_autofree char *line =3D NULL; size_t line_size =3D 0; FILE *fp; int copy_fd; @@ -715,12 +702,9 @@ openvz_copyfile(char* from_path, char* to_path) if (VIR_CLOSE(copy_fd) < 0) goto error; =20 - VIR_FREE(line); - return 0; =20 error: - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); VIR_FORCE_CLOSE(copy_fd); return -1; @@ -734,10 +718,10 @@ openvz_copyfile(char* from_path, char* to_path) int openvzCopyDefaultConfig(int vpsid) { - char *confdir =3D NULL; - char *default_conf_file =3D NULL; - char *configfile_value =3D NULL; - char *conf_file =3D NULL; + g_autofree char *confdir =3D NULL; + g_autofree char *default_conf_file =3D NULL; + g_autofree char *configfile_value =3D NULL; + g_autofree char *conf_file =3D NULL; int ret =3D -1; =20 if (openvzReadConfigParam(VZ_CONF_FILE, "CONFIGFILE", &configfile_valu= e) < 0) @@ -758,10 +742,6 @@ openvzCopyDefaultConfig(int vpsid) =20 ret =3D 0; cleanup: - VIR_FREE(confdir); - VIR_FREE(default_conf_file); - VIR_FREE(configfile_value); - VIR_FREE(conf_file); return ret; } =20 @@ -771,7 +751,7 @@ openvzCopyDefaultConfig(int vpsid) static int openvzLocateConfFileDefault(int vpsid, char **conffile, const char *ext) { - char *confdir; + g_autofree char *confdir =3D NULL; int ret =3D 0; =20 confdir =3D openvzLocateConfDir(); @@ -780,7 +760,6 @@ openvzLocateConfFileDefault(int vpsid, char **conffile,= const char *ext) =20 *conffile =3D g_strdup_printf("%s/%d.%s", confdir, vpsid, ext ? ext : = "conf"); =20 - VIR_FREE(confdir); return ret; } =20 @@ -828,8 +807,8 @@ openvz_readline(int fd, char *ptr, int maxlen) static int openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) { - char *conf_file; - char *line =3D NULL; + g_autofree char *conf_file =3D NULL; + g_autofree char *line =3D NULL; size_t line_size =3D 0; char *saveptr =3D NULL; char *uuidbuf; @@ -868,9 +847,7 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) } retval =3D 0; cleanup: - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); - VIR_FREE(conf_file); =20 return retval; } @@ -881,7 +858,7 @@ openvzGetVPSUUID(int vpsid, char *uuidstr, size_t len) int openvzSetDefinedUUID(int vpsid, unsigned char *uuid) { - char *conf_file; + g_autofree char *conf_file =3D NULL; char uuidstr[VIR_UUID_STRING_BUFLEN]; FILE *fp =3D NULL; int ret =3D -1; @@ -912,7 +889,6 @@ openvzSetDefinedUUID(int vpsid, unsigned char *uuid) ret =3D 0; cleanup: VIR_FORCE_FCLOSE(fp); - VIR_FREE(conf_file); return ret; } =20 @@ -941,7 +917,7 @@ static int openvzAssignUUIDs(void) { g_autoptr(DIR) dp =3D NULL; struct dirent *dent; - char *conf_dir; + g_autofree char *conf_dir =3D NULL; int vpsid; char *ext; int ret =3D 0; @@ -951,7 +927,6 @@ static int openvzAssignUUIDs(void) return -1; =20 if (virDirOpenQuiet(&dp, conf_dir) < 0) { - VIR_FREE(conf_dir); return 0; } =20 @@ -964,7 +939,6 @@ static int openvzAssignUUIDs(void) openvzSetUUID(vpsid); } =20 - VIR_FREE(conf_dir); return ret; } =20 --=20 2.34.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org