From patchwork Sun Mar 14 03:23:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4B3AC433DB for ; Sun, 14 Mar 2021 03:25:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 52BCE64DDE for ; Sun, 14 Mar 2021 03:25:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52BCE64DDE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHNM-0007Nc-GG for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:25:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMC-0006Sr-Cb for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:23:56 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:44773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMA-0004Oe-KT for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:23:56 -0500 Received: by mail-wm1-x32e.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so17443257wmi.3 for ; Sat, 13 Mar 2021 19:23:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2rnIQur47bUqEW0oQ7uZPNdfpmlBj++ZpXvn5yiPVOw=; b=QW3UbyXrUNi0DsP4sIz21ve0giEJ1Y95R38w7rbzSb4FbcYcIRJuG/JBHcrlVPuJoV 4dm1VCu1ZPWYatVwaLhdmUViW6BTAfpxejqPe8g7hoSeFqd3uRfg/4n6ZecwwEA4u8No b8CT9qxOdXxkM7WeoY7iY9eY7xqZg5U6Sgfyrpr7zfIegU5radvC4woYaE8+jBNrtA2H nGi8tL33ZkyMmpcuvFOdMI7NMymBuDJnuXLgwk3RslnvGGp4xPhrz9pUobDBeyRo9lny 3D39lK1dyJ1grYU8v8XdPeDMqmilsyBp+7OBYCkChRQSGciu/onlC69c+SvSKcQ3if7q y8LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2rnIQur47bUqEW0oQ7uZPNdfpmlBj++ZpXvn5yiPVOw=; b=AQmQdMm6Lqe1btAdZBqQLH7eFdDC20txGeaDNyq6YZh0zx17Klrkv6gZVR8BtmL5SF teurpM4zPHFQZHHL8D835MbfROxETSwrTcy7cQJRlpK+xyh4ErgACNmwdvhe6T1JOiCp a0ee/9pXEt4Zis7kufL8zwtIkv4vK/+VuzXpUZoj67uUjmyFmNl6kX9WQAAKr2KJnnJQ v5kjWK8H3M9r8XTJS7TrQWQ1S4L3wrfntN4ion0LqJr2AulfVd663bEaym6m3V5A+6Ea RA4c9w+3Vrg0BIeF9W1GsA7ivwqqYZ5PfubeG3J73n8kjIdVizuQdOBTTiV0to3QV3V0 iCTw== X-Gm-Message-State: AOAM532cd3OtpEXD7Mft3doknxXY5/WMB8fCbH4zpmOA1xydmArEcGL4 eTKQGr+AqE95yvZEx7LVjg6iFxE54ig= X-Google-Smtp-Source: ABdhPJxglU6hC5IdRe0q0K1qGVCCpORnCTZOjQxtQPFYT/Juxl8bqIWgZ8whmfTd+aHSP/TXRBze0Q== X-Received: by 2002:a1c:e244:: with SMTP id z65mr20079649wmg.130.1615692232156; Sat, 13 Mar 2021 19:23:52 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:23:51 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 1/8] bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants Date: Sun, 14 Mar 2021 05:23:17 +0200 Message-Id: <20210314032324.45142-2-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replaced the calls to malloc(), realloc(), and free() to their equivalents in GLib's allocation functions in various places. Signed-off-by: Mahmoud Mandour --- bsd-user/elfload.c | 74 +++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 5f4d824d78..7b0793693b 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -867,8 +867,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE) return ~(abi_ulong)0UL; - elf_phdata = (struct elf_phdr *) - malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum); + elf_phdata = g_try_new(struct elf_phdr, interp_elf_ex->ephnum) if (!elf_phdata) return ~((abi_ulong)0UL); @@ -878,7 +877,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, * we will be doing the wrong thing. */ if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) { - free(elf_phdata); + g_free(elf_phdata); return ~((abi_ulong)0UL); } @@ -891,7 +890,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, if (retval < 0) { perror("load_elf_interp"); exit(-1); - free (elf_phdata); + g_free(elf_phdata); return retval; } #ifdef BSWAP_NEEDED @@ -940,7 +939,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, if (error == -1) { /* Real error */ close(interpreter_fd); - free(elf_phdata); + g_free(elf_phdata); return ~((abi_ulong)0UL); } @@ -983,7 +982,7 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_FIXED|MAP_PRIVATE|MAP_ANON, -1, 0); } - free(elf_phdata); + g_free(elf_phdata); *interp_load_addr = load_addr; return ((abi_ulong) interp_elf_ex->e_entry) + load_addr; @@ -1064,24 +1063,24 @@ static void load_symbols(struct elfhdr *hdr, int fd) found: /* Now know where the strtab and symtab are. Snarf them. */ - s = malloc(sizeof(*s)); - syms = malloc(symtab.sh_size); + s = g_try_malloc(sizeof(*s)); + syms = g_try_malloc(symtab.sh_size); if (!syms) { - free(s); + g_free(s); return; } - s->disas_strtab = strings = malloc(strtab.sh_size); + s->disas_strtab = strings = g_malloc(strtab.sh_size); if (!s->disas_strtab) { - free(s); - free(syms); + g_free(s); + g_free(syms); return; } lseek(fd, symtab.sh_offset, SEEK_SET); if (read(fd, syms, symtab.sh_size) != symtab.sh_size) { - free(s); - free(syms); - free(strings); + g_free(s); + g_free(syms); + g_free(strings); return; } @@ -1113,11 +1112,11 @@ static void load_symbols(struct elfhdr *hdr, int fd) that we threw away. Whether or not this has any effect on the memory allocation depends on the malloc implementation and how many symbols we managed to discard. */ - new_syms = realloc(syms, nsyms * sizeof(*syms)); + new_syms = g_try_realloc(syms, nsyms * sizeof(*syms)); if (new_syms == NULL) { - free(s); - free(syms); - free(strings); + g_free(s); + g_free(syms); + g_free(strings); return; } syms = new_syms; @@ -1126,9 +1125,9 @@ static void load_symbols(struct elfhdr *hdr, int fd) lseek(fd, strtab.sh_offset, SEEK_SET); if (read(fd, strings, strtab.sh_size) != strtab.sh_size) { - free(s); - free(syms); - free(strings); + g_free(s); + g_free(syms); + g_free(strings); return; } s->disas_num_syms = nsyms; @@ -1190,7 +1189,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, } /* Now read in all of the header information */ - elf_phdata = (struct elf_phdr *)malloc(elf_ex.e_phentsize*elf_ex.e_phnum); + elf_phdata = + (struct elf_phdr *)g_try_malloc(elf_ex.e_phentsizei * elf_ex.e_phnum); if (elf_phdata == NULL) { return -ENOMEM; } @@ -1204,7 +1204,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, if (retval < 0) { perror("load_elf_binary"); exit(-1); - free (elf_phdata); + g_free(elf_phdata); return -errno; } @@ -1231,8 +1231,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, if (elf_ppnt->p_type == PT_INTERP) { if ( elf_interpreter != NULL ) { - free (elf_phdata); - free(elf_interpreter); + g_free(elf_phdata); + g_free(elf_interpreter); close(bprm->fd); return -EINVAL; } @@ -1242,10 +1242,10 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, * is an a.out format binary */ - elf_interpreter = (char *)malloc(elf_ppnt->p_filesz); + elf_interpreter = (char *)g_try_malloc(elf_ppnt->p_filesz); if (elf_interpreter == NULL) { - free (elf_phdata); + g_free(elf_phdata); close(bprm->fd); return -ENOMEM; } @@ -1298,8 +1298,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, if (retval < 0) { perror("load_elf_binary3"); exit(-1); - free (elf_phdata); - free(elf_interpreter); + g_free(elf_phdata); + g_free(elf_interpreter); close(bprm->fd); return retval; } @@ -1323,8 +1323,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, } if (!interpreter_type) { - free(elf_interpreter); - free(elf_phdata); + g_free(elf_interpreter); + g_free(elf_phdata); close(bprm->fd); return -ELIBBAD; } @@ -1346,8 +1346,8 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, } } if (!bprm->p) { - free(elf_interpreter); - free (elf_phdata); + g_free(elf_interpreter); + g_free(elf_phdata); close(bprm->fd); return -E2BIG; } @@ -1486,17 +1486,17 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, reloc_func_desc = interp_load_addr; close(interpreter_fd); - free(elf_interpreter); + g_free(elf_interpreter); if (elf_entry == ~((abi_ulong)0UL)) { printf("Unable to load interpreter\n"); - free(elf_phdata); + g_free(elf_phdata); exit(-1); return 0; } } - free(elf_phdata); + g_free(elf_phdata); if (qemu_log_enabled()) load_symbols(&elf_ex, bprm->fd); From patchwork Sun Mar 14 03:23:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29D1AC433DB for ; Sun, 14 Mar 2021 03:26:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C17864DDE for ; Sun, 14 Mar 2021 03:26:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C17864DDE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHP2-0000mz-QP for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:26:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMH-0006V2-6C for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:01 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:37658) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMF-0004Qa-8F for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:00 -0500 Received: by mail-wm1-x331.google.com with SMTP id f22-20020a7bc8d60000b029010c024a1407so18142586wml.2 for ; Sat, 13 Mar 2021 19:23:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jsATIuWJVLsP36O5rVx7aqqo47uS9kRVIQPzX/a9z+M=; b=h47gePfWpVLTlLPeqZkKtPpprzcttqNm4iqD709FU3AmUNx5hZF7Ma5GzOUvsuXdE0 x4mwtwFfcDugY+XLj22iWPLYPll3qqoyQw46nZzht2aqWaYbUoelLvO0hvlNB6u9LXh7 74GU9z+9h4A1Vf/fYlj0nb6hIFvaqSN45IBa8eJzXtitgwW2GkRMCW5lUiKPt7ffFeRH LcXqbDX3TQyRXAjIe3841bnbXBV2SUwfq0S44Ul+Rq6cl/QlDGNRkwXMN0MuCbIW77w/ 6thnQtdpZ2tR3XigZTxAOhpUloTSj69BmJIG03aJbVHkXSLk2nOEwzaCvBRUpRPfCIkq nmQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jsATIuWJVLsP36O5rVx7aqqo47uS9kRVIQPzX/a9z+M=; b=DXILvivAyzEG6VRgb0B49H0FDgX0sfMc4ZpqxaS9OfEUHbLUq8IJmhIzWF1CmGq7ih 1kYVaDYd2xCDmFQuMa7rmts2Ll4a0rTEX2w6LzkSHz/rAXcoeokwROtMlyQ/SV3ImCdo xGpuv2793aoJg174aNtJtknZ0ArY5JxctyYB5u0ck1qBeopjvFYQA2def21RsLw6uGmu uT8CqCLZewoIRMlOOFKWv2RoQv32I6zTiab1HwkAfsW6bVDfzMqHkBYxWoZVXr1WM13R cKDabf4nlUFLPX9y/k7onndKQGKKByKsC+knzJjpSdBa92rqwl3x0cJcomSiN1o0ZBOi FTWw== X-Gm-Message-State: AOAM532ymiv6+L7UOfo1o2mGqHntN5zofqPXuLQoULbF2wpeZZ2iDB+S 6SJ+l7AGAlCU47HU9+gx4fFJRjgAbJg= X-Google-Smtp-Source: ABdhPJzqIDzR+OfYBW1hXWgNXuwHYHW1Ydm/6WN4sD2new6S/6A72iUdabFtAqRUo+oDaMfAx5rTfQ== X-Received: by 2002:a1c:3954:: with SMTP id g81mr17364503wma.170.1615692236853; Sat, 13 Mar 2021 19:23:56 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:23:56 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 2/8] hw/audio/fmopl.c: Fixing some style errors Date: Sun, 14 Mar 2021 05:23:18 +0200 Message-Id: <20210314032324.45142-3-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x331.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , Gerd Hoffmann Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Fixed style errors on the relevant lines in which I will introduce changes. Signed-off-by: Mahmoud Mandour --- hw/audio/fmopl.c | 58 ++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c index 8a71a569fa..51b773695a 100644 --- a/hw/audio/fmopl.c +++ b/hw/audio/fmopl.c @@ -607,26 +607,32 @@ static int OPLOpenTable( void ) double pom; /* allocate dynamic tables */ - if( (TL_TABLE = malloc(TL_MAX*2*sizeof(int32_t))) == NULL) - return 0; - if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(int32_t *))) == NULL) - { - free(TL_TABLE); - return 0; - } - if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(int32_t))) == NULL) - { - free(TL_TABLE); - free(SIN_TABLE); - return 0; - } - if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(int32_t))) == NULL) - { - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); - return 0; - } + TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t)); + if (TL_TABLE == NULL) { + return 0; + } + + SIN_TABLE = malloc(SIN_ENT * 4 * sizeof(int32_t *)); + if (SIN_TABLE == NULL) { + free(TL_TABLE); + return 0; + } + + AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t)); + if (AMS_TABLE == NULL) { + free(TL_TABLE); + free(SIN_TABLE); + return 0; + } + + VIB_TABLE = malloc(VIB_ENT * 2 * sizeof(int32_t)); + if (VIB_TABLE == NULL) { + free(TL_TABLE); + free(SIN_TABLE); + free(AMS_TABLE); + return 0; + } + ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1); /* make total level table */ for (t = 0;t < EG_ENT-1 ;t++){ @@ -696,10 +702,10 @@ static int OPLOpenTable( void ) static void OPLCloseTable( void ) { g_free(ENV_CURVE); - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); - free(VIB_TABLE); + free(TL_TABLE); + free(SIN_TABLE); + free(AMS_TABLE); + free(VIB_TABLE); } /* CSM Key Control */ @@ -1082,7 +1088,7 @@ FM_OPL *OPLCreate(int clock, int rate) state_size = sizeof(FM_OPL); state_size += sizeof(OPL_CH)*max_ch; /* allocate memory block */ - ptr = malloc(state_size); + ptr = malloc(state_size); if(ptr==NULL) return NULL; /* clear */ memset(ptr,0,state_size); @@ -1128,7 +1134,7 @@ void OPLDestroy(FM_OPL *OPL) } #endif OPL_UnLockTable(); - free(OPL); + free(OPL); } /* ---------- Option handlers ---------- */ From patchwork Sun Mar 14 03:23:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C65CC433E0 for ; Sun, 14 Mar 2021 03:26:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5628164DDE for ; Sun, 14 Mar 2021 03:26:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5628164DDE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHON-0000EL-4x for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:26:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMH-0006Vc-H6 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:02 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:37220) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMF-0004RU-C3 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:01 -0500 Received: by mail-wr1-x42c.google.com with SMTP id v15so6907456wrx.4 for ; Sat, 13 Mar 2021 19:23:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BajUyfK396v7XdGJs5VK12t0TqFac+fXAWp2W7CZvi4=; b=NYw4mxvsGbWYnB32qoBuO35zU5yhFGs3LLivuPZslQd9Ddqw9I36e/l8MFygj0xOcc yZU1ppsm1zuQXYzieL6JuI4UzS7HyBVSbtFgWXhxGIR21XSLcMsyBleWtooI5nsarfEv BHSUd03doGa9h/X6DTnFyN4hnFewx8V871ycyPZRZp1D/F9BNV5qzWHjWz+MnMIeKOlO fqG1wB9pvEcsfuP3hn34hySwb4JMLnymABvwX/hX4aaZ47K8iCol+UM4WFH0ZLBfXPyV x5Ey7E8qf91NekepLqPgRcBkG7j/viiKOwhQVbzydIXR3MUfnorpaSxoqgKSVur7h1e9 1yaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BajUyfK396v7XdGJs5VK12t0TqFac+fXAWp2W7CZvi4=; b=Twu7ytU/oZWS29eXmkiDbddhDk1Dt4QyAs0e5hamRaknfRvIqoWrt7h6erK6QhJSRG y3Ly5Uxhk6HdOVXg40QOhc/HOIapyJu1sjq/5yZO0MvBhA0y3JfHEX+6540gJearPLty LhcsywkzbdHeXyYMoKgwq8zGVn0gEJJoAZMpM/bHSxOyW0x+Lw2gF/6RvEPyReWhxUKg 4tIN9a9yK0M+spsCIZNksXnK8rXaOMb/vimQhm3gdEdtl9NH3ZNASufHH86Y84jiJWm7 Ilx6cjNlOkfD55iPwhfSHUA/v/RfnKY+/+kuyliHNHAONi6yjDNRA0y78s5gZENXNgpV fkgw== X-Gm-Message-State: AOAM532eMna3y1Cqtrr6LAYlEvcUqOrY0AJUAWKC+4DR9VXktUKBEbSg NSUF330qIpK9XRmpyQpL1eohHfFKOSc= X-Google-Smtp-Source: ABdhPJyQiBG3C3mbSJVJ6DguNxzXLhDF91H+STCd7xv8rLaUhXvLS4A96xNipLEbjQ59LqNoemRiBw== X-Received: by 2002:a5d:570b:: with SMTP id a11mr21299224wrv.281.1615692237926; Sat, 13 Mar 2021 19:23:57 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.23.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:23:57 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 3/8] hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants Date: Sun, 14 Mar 2021 05:23:19 +0200 Message-Id: <20210314032324.45142-4-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , Gerd Hoffmann Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replaced calls to malloc(), and free() to their equivalent allocation functions from GLib. Also added checking for null after ENV_CURVE allocation following the same pattern of checking on preceeding table allocations. Signed-off-by: Mahmoud Mandour --- hw/audio/fmopl.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c index 51b773695a..795c7a23dc 100644 --- a/hw/audio/fmopl.c +++ b/hw/audio/fmopl.c @@ -607,33 +607,41 @@ static int OPLOpenTable( void ) double pom; /* allocate dynamic tables */ - TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t)); + TL_TABLE = g_try_new(int32_t, TL_MAX * 2); if (TL_TABLE == NULL) { return 0; } - SIN_TABLE = malloc(SIN_ENT * 4 * sizeof(int32_t *)); + SIN_TABLE = g_try_new(int32_t *, SIN_ENT * 4); if (SIN_TABLE == NULL) { - free(TL_TABLE); + g_free(TL_TABLE); return 0; } - AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t)); + AMS_TABLE = g_try_new(int32_t, AMS_ENT * 2); if (AMS_TABLE == NULL) { - free(TL_TABLE); - free(SIN_TABLE); + g_free(TL_TABLE); + g_free(SIN_TABLE); return 0; } - VIB_TABLE = malloc(VIB_ENT * 2 * sizeof(int32_t)); + VIB_TABLE = g_try_new(int32_t, VIB_ENT * 2); if (VIB_TABLE == NULL) { - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); + g_free(TL_TABLE); + g_free(SIN_TABLE); + g_free(AMS_TABLE); + return 0; + } + + ENV_CURVE = g_try_new(int32_t, 2 * EG_ENT + 1); + if (ENV_CURVE == NULL) { + g_free(TL_TABLE); + g_free(SIN_TABLE); + g_free(AMS_TABLE); + g_free(VIB_TABLE); return 0; } - ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1); /* make total level table */ for (t = 0;t < EG_ENT-1 ;t++){ rate = ((1< voltage */ @@ -702,10 +710,10 @@ static int OPLOpenTable( void ) static void OPLCloseTable( void ) { g_free(ENV_CURVE); - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); - free(VIB_TABLE); + g_free(TL_TABLE); + g_free(SIN_TABLE); + g_free(AMS_TABLE); + g_free(VIB_TABLE); } /* CSM Key Control */ @@ -1088,7 +1096,7 @@ FM_OPL *OPLCreate(int clock, int rate) state_size = sizeof(FM_OPL); state_size += sizeof(OPL_CH)*max_ch; /* allocate memory block */ - ptr = malloc(state_size); + ptr = g_try_malloc(state_size); if(ptr==NULL) return NULL; /* clear */ memset(ptr,0,state_size); @@ -1134,7 +1142,7 @@ void OPLDestroy(FM_OPL *OPL) } #endif OPL_UnLockTable(); - free(OPL); + g_free(OPL); } /* ---------- Option handlers ---------- */ From patchwork Sun Mar 14 03:23:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57D0EC433DB for ; Sun, 14 Mar 2021 03:28:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EBB7664EC6 for ; Sun, 14 Mar 2021 03:28:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBB7664EC6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHQI-0002Xq-3D for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:28:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMJ-0006Vt-5W for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:04 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:34473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMG-0004RY-Tt for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:02 -0500 Received: by mail-wr1-x434.google.com with SMTP id j7so3901968wrd.1 for ; Sat, 13 Mar 2021 19:24:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=03j/gt08iEmB/YpVMydgNMGaK1/oqVMzCnaDLB+XL7M=; b=Ii/byVoiSpzMkxd5JVFe+mKtH7ToN1dOHdaNLTKmYLx9njMUCC2Z7dinJf/eUcHotO mAWmLX4kSV5zmWeWjyZTzd199D2xnGybLV1qZK64u47Xa6VZu0B6X9iG2eoe4hKdyICb qk4pZLffEfmWMCk1LfoCgp/ml3ssWSmriTrsFGKFv0ZH5lALxNtLkmVR21MlU055hi5b dWXXj340OU/lEv/KBjzzgklVHdRkUHpwHkt7jzR6U7guWU15v3YdmTDOjqKGnSM4tBFs uvY9ZjPPDKfB81tg+e9BpXoXidnMulHzfvBF5SYWTHkGyQjHpuBvniU6I10M3ksTV3Ej 4i+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=03j/gt08iEmB/YpVMydgNMGaK1/oqVMzCnaDLB+XL7M=; b=moon2JVmukL192HcFy4lwvkbRFgo7VnA2hZe7cS4YT0WlVh00fGWpoKiRAkkwkxnUT o+1mN9Z1UYy+O0WPZqEQknSikvD3smwKKKp9kCXKiNSFhqWgOf58qjpwORX9E7KGP+Fu XbMoFTwXi6KVc2ePT6f+ir2JXT2I0LCKVx2UPbGOjsDlTcTGtqj8Y50jR9ZLeiHf8/Qn Mb8UQbeWQ8Qk/LBpkX2zJBkr2gaqfdW6QhDIKr5txUSoswoRrwXL4jVj+mD1FTBDPWpz TiEHx9L4jRECJRuHoPL+4vdTod2iVNVhrfl+psJppaEhSIknO+WExqaD0Lr1JBaHnd9U SBKQ== X-Gm-Message-State: AOAM53288aV25LNQqUMxiwy6SVZnJRth2feGVpqibVOpoX4Wcdi94pdU y5fCxvGWqz1s+SUPPm9r9GdCgVt76Ms= X-Google-Smtp-Source: ABdhPJxCIdAjkcprtUcVribnivMJvBU3iHeU1ToyMfX/M18v1lHWN9FWNazHtLWSfV2adr1VBTzppw== X-Received: by 2002:a5d:6b50:: with SMTP id x16mr5420011wrw.379.1615692239020; Sat, 13 Mar 2021 19:23:59 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:23:58 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 4/8] target/xtensa: Replaced malloc/free with GLib's variants Date: Sun, 14 Mar 2021 05:23:20 +0200 Message-Id: <20210314032324.45142-5-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Mahmoud Mandour Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replaced the calls to malloc() and their respective calls to free() with GLib's allocation and deallocation functions. Removed null checking before calling g_free() because it's not necessary and generates style errors. Signed-off-by: Mahmoud Mandour Acked-by: Max Filippov --- target/xtensa/xtensa-isa.c | 53 +++++++++++++++----------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/target/xtensa/xtensa-isa.c b/target/xtensa/xtensa-isa.c index 630b4f9da1..5afdba77aa 100644 --- a/target/xtensa/xtensa-isa.c +++ b/target/xtensa/xtensa-isa.c @@ -79,7 +79,7 @@ int xtensa_insnbuf_size(xtensa_isa isa) xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa) { xtensa_insnbuf result = (xtensa_insnbuf) - malloc(xtensa_insnbuf_size(isa) * sizeof(xtensa_insnbuf_word)); + g_try_malloc(xtensa_insnbuf_size(isa) * sizeof(xtensa_insnbuf_word)); CHECK_ALLOC(result, 0); return result; @@ -89,7 +89,7 @@ xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa) void xtensa_insnbuf_free(xtensa_isa isa __attribute__ ((unused)), xtensa_insnbuf buf) { - free(buf); + g_free(buf); } @@ -237,7 +237,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, /* Set up the opcode name lookup table. */ isa->opname_lookup_table = - malloc(isa->num_opcodes * sizeof(xtensa_lookup_entry)); + g_try_new(xtensa_lookup_entry, isa->num_opcodes); CHECK_ALLOC_FOR_INIT(isa->opname_lookup_table, NULL, errno_p, error_msg_p); for (n = 0; n < isa->num_opcodes; n++) { isa->opname_lookup_table[n].key = isa->opcodes[n].name; @@ -248,7 +248,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, /* Set up the state name lookup table. */ isa->state_lookup_table = - malloc(isa->num_states * sizeof(xtensa_lookup_entry)); + g_try_new(xtensa_lookup_entry, isa->num_states); CHECK_ALLOC_FOR_INIT(isa->state_lookup_table, NULL, errno_p, error_msg_p); for (n = 0; n < isa->num_states; n++) { isa->state_lookup_table[n].key = isa->states[n].name; @@ -259,7 +259,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, /* Set up the sysreg name lookup table. */ isa->sysreg_lookup_table = - malloc(isa->num_sysregs * sizeof(xtensa_lookup_entry)); + g_try_new(xtensa_lookup_entry, isa->num_sysregs); CHECK_ALLOC_FOR_INIT(isa->sysreg_lookup_table, NULL, errno_p, error_msg_p); for (n = 0; n < isa->num_sysregs; n++) { isa->sysreg_lookup_table[n].key = isa->sysregs[n].name; @@ -271,7 +271,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, /* Set up the user & system sysreg number tables. */ for (is_user = 0; is_user < 2; is_user++) { isa->sysreg_table[is_user] = - malloc((isa->max_sysreg_num[is_user] + 1) * sizeof(xtensa_sysreg)); + g_try_new(xtensa_sysreg, isa->max_sysreg_num[is_user] + 1); CHECK_ALLOC_FOR_INIT(isa->sysreg_table[is_user], NULL, errno_p, error_msg_p); @@ -290,7 +290,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, /* Set up the interface lookup table. */ isa->interface_lookup_table = - malloc(isa->num_interfaces * sizeof(xtensa_lookup_entry)); + g_try_new(xtensa_lookup_entry, isa->num_interfaces); CHECK_ALLOC_FOR_INIT(isa->interface_lookup_table, NULL, errno_p, error_msg_p); for (n = 0; n < isa->num_interfaces; n++) { @@ -302,7 +302,7 @@ xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, /* Set up the funcUnit lookup table. */ isa->funcUnit_lookup_table = - malloc(isa->num_funcUnits * sizeof(xtensa_lookup_entry)); + g_try_new(xtensa_lookup_entry, isa->num_funcUnits); CHECK_ALLOC_FOR_INIT(isa->funcUnit_lookup_table, NULL, errno_p, error_msg_p); for (n = 0; n < isa->num_funcUnits; n++) { @@ -332,36 +332,25 @@ void xtensa_isa_free(xtensa_isa isa) * structure to its initial state. */ - if (intisa->opname_lookup_table) { - free(intisa->opname_lookup_table); - intisa->opname_lookup_table = 0; - } + g_free(intisa->opname_lookup_table); + intisa->opname_lookup_table = 0; - if (intisa->state_lookup_table) { - free(intisa->state_lookup_table); - intisa->state_lookup_table = 0; - } + g_free(intisa->state_lookup_table); + intisa->state_lookup_table = 0; + + g_free(intisa->sysreg_lookup_table); + intisa->sysreg_lookup_table = 0; - if (intisa->sysreg_lookup_table) { - free(intisa->sysreg_lookup_table); - intisa->sysreg_lookup_table = 0; - } for (n = 0; n < 2; n++) { - if (intisa->sysreg_table[n]) { - free(intisa->sysreg_table[n]); - intisa->sysreg_table[n] = 0; - } + g_free(intisa->sysreg_table[n]); + intisa->sysreg_table[n] = 0; } - if (intisa->interface_lookup_table) { - free(intisa->interface_lookup_table); - intisa->interface_lookup_table = 0; - } + g_free(intisa->interface_lookup_table); + intisa->interface_lookup_table = 0; - if (intisa->funcUnit_lookup_table) { - free(intisa->funcUnit_lookup_table); - intisa->funcUnit_lookup_table = 0; - } + g_free(intisa->funcUnit_lookup_table); + intisa->funcUnit_lookup_table = 0; } From patchwork Sun Mar 14 03:23:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C460FC433E0 for ; Sun, 14 Mar 2021 03:27:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5151A64DDE for ; Sun, 14 Mar 2021 03:27:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5151A64DDE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHPj-0001y4-BL for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:27:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMK-0006XF-8K for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:04 -0500 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:52897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMH-0004SU-Hq for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:04 -0500 Received: by mail-wm1-x335.google.com with SMTP id d191so6054668wmd.2 for ; Sat, 13 Mar 2021 19:24:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ULb0qQJUebEUkzQmRP5LxPxlhhbE/qPxwsfl/mciK6w=; b=IZpnYbQCRmVXF5uhIjhIZcymB+m/+BcS4dI9REG29zDjOwpKgx+T+rEFslPGY0i/9j N8RrqqWTUQM8/1Ys5VcJPjmHDpWh1CW0pkcT5j+sMtqmJQIQkk+VFfl7EAvapUMy0AeA 1QcauFJGg3PG/k3YSG7g88qUV+2dDmGTeTRpkpSKVuC9dniD34m0lsQd4eUPKfud8H8V HlWc8ouwQ27JNKfB8mveApEGJSDNVwaQ79i7J7BnR0tBhHDjMcHPdpPYGkH6IhLiSdcg YD2QmiS0ugYZUh7x5m8QKoYvGNRHjPn5/AoPpg/kyldYADkPu5Ayigsbl4atFTyOrB9x 1Tcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ULb0qQJUebEUkzQmRP5LxPxlhhbE/qPxwsfl/mciK6w=; b=P+YL4EeFZ8eQa0CAk9Ozd/m/FHUWoD5DWYKHI2HbENsqdKmYc+4YzZ6ZY3m9gM3dkv 0YHIOZLM7YZnkCp8LogscWzRerLYyYPalwUb0SmW7hDFPoQkANxhf1a4i1eqZ7trFmm4 +GXI5EJTzdtH/6i66+dlkuyAbmwCGS3hmb9WdeK2ZV+kVKBMG9Bda8C0VwYzJeU2Or78 D44Xa+JT7d3aEcUg5/2rhBAvTRdme9AO1E1O/IhiBIMhXp4wIWyora/AIE8BDvx3nQ0d P9nTFsZLlDDAUShXJOgFQRE3kQ3SLeFgsiQ9cRiiEsy07cc4n9O16eAEi+sLIeVS9ixz DOrQ== X-Gm-Message-State: AOAM533HclR3HwHK5r5ThWeVFtW/DHX82sv4xVeww18ZfApPn1g1fx2H Qkdw4WOp9J6ub1bvPe54CRjSJFBW7pg= X-Google-Smtp-Source: ABdhPJzkO11Wgy1Gb1TPHHEW8R2fRpofdOGJ1FFdHVLl9IHD1TVoNdkRGTN5Jj88I9KH6hdW1Uw2Ug== X-Received: by 2002:a1c:bc56:: with SMTP id m83mr20210266wmf.174.1615692240129; Sat, 13 Mar 2021 19:24:00 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:23:59 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 5/8] util/compatfd.c: Replaced a malloc with GLib's variant Date: Sun, 14 Mar 2021 05:23:21 +0200 Message-Id: <20210314032324.45142-6-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replaced a malloc() call and its respective free() call with GLib's g_try_malloc() and g_free(). Also, did slight styling changes that were producing style errors when using the checkpatch.pl script against the file. Signed-off-by: Mahmoud Mandour --- util/compatfd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/compatfd.c b/util/compatfd.c index ee47dd8089..834ddd0573 100644 --- a/util/compatfd.c +++ b/util/compatfd.c @@ -20,8 +20,7 @@ #include #endif -struct sigfd_compat_info -{ +struct sigfd_compat_info { sigset_t mask; int fd; }; @@ -53,8 +52,9 @@ static void *sigwait_compat(void *opaque) len = write(info->fd, (char *)&buffer + offset, sizeof(buffer) - offset); - if (len == -1 && errno == EINTR) + if (len == -1 && errno == EINTR) { continue; + } if (len <= 0) { return NULL; @@ -72,14 +72,14 @@ static int qemu_signalfd_compat(const sigset_t *mask) QemuThread thread; int fds[2]; - info = malloc(sizeof(*info)); + info = g_try_malloc(sizeof(*info)); if (info == NULL) { errno = ENOMEM; return -1; } if (pipe(fds) == -1) { - free(info); + g_free(info); return -1; } From patchwork Sun Mar 14 03:23:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18777C433DB for ; Sun, 14 Mar 2021 03:29:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B81496157F for ; Sun, 14 Mar 2021 03:29:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B81496157F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:51686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHRJ-0004Ha-Tl for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:29:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMK-0006XP-Vt for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:06 -0500 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:35664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMI-0004Sx-Tm for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:04 -0500 Received: by mail-wm1-x336.google.com with SMTP id c76-20020a1c9a4f0000b029010c94499aedso18133291wme.0 for ; Sat, 13 Mar 2021 19:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FBWETjBx7yR8JhCne1xrs11sERKEjTujz/IcxswUR6c=; b=PeQlarZHA8Q8SVrhCYuFtqbkvRlPrf7SMWwPYTOJ5qrLNlJiREAVqglAgKh4BGLLke mDnMmofpYYpzJi2WIf640C8ZW+gLZjuga6n4422KlQ+HC1R8Q+bPfYPJCMTmIqS2K6A6 F6TlLkRQ2ROJQp1Dya54MF44IL6J428c/SNG+shu0v3omt/WLB/K/Ube9w4Wq4qYbk5J MwD3tU4Mv+EitCFRI+ZyiFT+yMQF73L/LJw19HmMOWIbSypRiD9Mfgs7XyKtpZvCtMCp quDMD8pQXWGKMpS4AL5NIg3OvRD4eYsc1opn/UyBkhG/gYxXcsQVOWZCxB+R5eCoDd0S 4gxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FBWETjBx7yR8JhCne1xrs11sERKEjTujz/IcxswUR6c=; b=PxBuSz+rHvvXFmOGL9ccsTbYdE3cj7BGgEzy7Z8etFz2l06lvL38xzVsorc9cieetS QrzStqG9IRWAgb1mV7Nq0hsK8NdjjIqw7hMN7kEwd71GZpgxybeEjy1fqOLluSexStNr oZs55nd07AahvdkTzyjjhwrL7eR1VUHU740FtNcyKKVbEymyOShw+vkQ4U+WwthHrsCl ocqrSDq2mXd5IUZ0GmC8Xm4MnlpJwZvPthnfENPtkOgna4lXmSd62nlk9zOv+zZuozI+ jSw9H4iHNxwz5+/qOgBH0uivHAyxf8fjWMZ0E+WZ9u/YcEK1FA1klK+s/Xiwkbo3V3+Y sc1A== X-Gm-Message-State: AOAM531asKALMpTD/nxNXcEkiSDjcinBoh9JEheTaQBmfAIgdvc7yocW W50vyEXYmM57Ee+748oQpEuOGXwFQkw= X-Google-Smtp-Source: ABdhPJxdIXS+YrhlhQAMGO2tdAUOEpd7VE+G4qViNr/uNDCzhPVD9kOL0KJCgnN8zxSi5wP0E0eOpg== X-Received: by 2002:a05:600c:2282:: with SMTP id 2mr20082767wmf.93.1615692241253; Sat, 13 Mar 2021 19:24:01 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:24:00 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 6/8] tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0 Date: Sun, 14 Mar 2021 05:23:22 +0200 Message-Id: <20210314032324.45142-7-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replaced a call to calloc() and its respective free() call with GLib's g_try_new0() and g_free() calls. Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c index 874f01c488..b5f04be356 100644 --- a/tools/virtiofsd/buffer.c +++ b/tools/virtiofsd/buffer.c @@ -37,7 +37,7 @@ static ssize_t fuse_buf_writev(struct fuse_buf *out_buf, struct iovec *iov; int fd = out_buf->fd; - iov = calloc(iovcnt, sizeof(struct iovec)); + iov = g_try_new0(struct iovec, iovcnt); if (!iov) { return -ENOMEM; } @@ -61,7 +61,7 @@ static ssize_t fuse_buf_writev(struct fuse_buf *out_buf, res = -errno; } - free(iov); + g_free(iov); return res; } From patchwork Sun Mar 14 03:23:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACFB8C433DB for ; Sun, 14 Mar 2021 03:28:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 48C736157F for ; Sun, 14 Mar 2021 03:28:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48C736157F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHQx-0003gO-Ew for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:28:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMM-0006Xp-Eh for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:06 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:37225) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMK-0004T3-0l for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:06 -0500 Received: by mail-wr1-x431.google.com with SMTP id v15so6907495wrx.4 for ; Sat, 13 Mar 2021 19:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oCmAvra+9pdnWt5HPQ7qb167aeUA8Zrq2LTIBRXk/CU=; b=C3fsQZjWINmodDF5RjZxzhEd867S9ad8EMBpBOK2Q7+q0isd3NK5dpbHqqq/9X3AYn CcZEsBitKYwCAgZFnErz4cGLCGU4VSgU1Yl2Ed2aUYr2kHpCvSsS86o3UHUTOfsP52sJ eylXltFmu1TprHKNng/SHnUnq+evSNxJ8HDmKs8zG/TPTBKdUe+UkW5aH/oWZay2YDMj HWjKjptNKXdYLWWee94gbQ/mwkncslEz2hoZiHVBaggIyVrctQ1mb+pVEi4m+qgx8+Nr htws7uf58LEKJnmFgmX7pHkKsDvE1ZfdDEkb5nrOn1gegQ7TZDWFcojxWWFJyz9micG1 cFTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oCmAvra+9pdnWt5HPQ7qb167aeUA8Zrq2LTIBRXk/CU=; b=KbEo6JjTOpFXDVo8inZFWphGWs+q/tAKelHnq7JScHmRJzL3EE17iA6l8oXeMbq8Te CGvkoLRU85BX4z4NujboE8P7S/5QmLdsZaW3SsWr+4GLCSwEOH4scbV9yo4u3RHnyC+U gWEWGoDFsxC4Fu4bENECiwGW63Ej29QKa8wRRXRvxQJDZYpqCETWRI13fzATHOZOUd9W 82Of7kHk4F9D2SKm3L04FI54Dlz0s+a8HtJTawXKXOdBJIYOrJT6qaPTXU7PRMSAf/KK Wz9a0pEP7h4kfKB34g5J36v4Od4juOPb0L7XVaTNf6kZEHzFvWbtsDkcAXOhauTfXgpp 3JFA== X-Gm-Message-State: AOAM530wvd6nc0pMroqhTtjEyX8VPo/e4REWBpIBIjUJAkTeSwDOHb32 ZNmFq5UAZhebpA6dv2axAxN0xr5e3ac= X-Google-Smtp-Source: ABdhPJwNvu/QQE13zP/lB4aBNUJaPdXgPka47jUDe77Ix3n87gJ/PuI3hmAVV2WdMnMfqOuU1A62sw== X-Received: by 2002:a5d:6290:: with SMTP id k16mr20354363wru.177.1615692242460; Sat, 13 Mar 2021 19:24:02 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:24:02 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 7/8] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc Date: Sun, 14 Mar 2021 05:23:23 +0200 Message-Id: <20210314032324.45142-8-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Replaced a malloc() call and its respective free() with GLib's g_try_malloc() and g_free() calls. Signed-off-by: Mahmoud Mandour Reviewed-by: Stefan Hajnoczi --- tools/virtiofsd/fuse_opt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/virtiofsd/fuse_opt.c b/tools/virtiofsd/fuse_opt.c index f0ab8d22f4..9d371448e9 100644 --- a/tools/virtiofsd/fuse_opt.c +++ b/tools/virtiofsd/fuse_opt.c @@ -272,7 +272,7 @@ static int process_opt_sep_arg(struct fuse_opt_context *ctx, } param = ctx->argv[ctx->argctr]; - newarg = malloc(sep + strlen(param) + 1); + newarg = g_try_malloc(sep + strlen(param) + 1); if (!newarg) { return alloc_failed(); } @@ -280,7 +280,7 @@ static int process_opt_sep_arg(struct fuse_opt_context *ctx, memcpy(newarg, arg, sep); strcpy(newarg + sep, param); res = process_opt(ctx, opt, sep, newarg, iso); - free(newarg); + g_free(newarg); return res; } From patchwork Sun Mar 14 03:23:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 12137175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0823C433DB for ; Sun, 14 Mar 2021 03:29:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 530526157F for ; Sun, 14 Mar 2021 03:29:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 530526157F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLHRw-0005JE-H3 for qemu-devel@archiver.kernel.org; Sat, 13 Mar 2021 22:29:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLHMO-0006YS-QT for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:09 -0500 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:39644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lLHMM-0004TE-78 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 22:24:08 -0500 Received: by mail-wm1-x330.google.com with SMTP id 124-20020a1c00820000b029010b871409cfso18126360wma.4 for ; Sat, 13 Mar 2021 19:24:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mktypJvu/1F6oyY228R0OtNNmqjKKSzXTpTB6Y2kEiY=; b=lJ+JDP2UnJpvyBNe0cBpfBUBwhyPhZHBnqHAfQ9vRxnseAU7MSxw8j6FVvFGyQyrQo vLC65EQJ6JAj7C6kLA7AYwV7j+IIMYM7WzssHHRNt/yNK/bKfjgEYiqtEknIm6itLnn+ QDe+HeiGYIMQ5Sa3avjqmls8TFvxpEMzIZiTzTLYApVqri+1NLRFUAOok3uWmq/KN8Bo KSYrqKbU+8VzINyDiPajDftO9a/jp7W8ByVYfQS2TKtF6QmHxN11BCDO433hN9DJtPrZ 3tWR/+s3rdDGAxdhyKwQD7sZFmvAIEpQRqC6DZFzmuOUyeg317p7FZR0P9DKUlOfXSj1 A8Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mktypJvu/1F6oyY228R0OtNNmqjKKSzXTpTB6Y2kEiY=; b=TwTq8lcux6CImm5L9fz0Jek27j0xhZjaxGQeOJiBuM3qcN4g+ykvsuJlDqNkDsyi82 vMGvP/CuZ5CsI3ldPZI5rJRNJM+fDsAy+AIkgs+W0EZehHu3WPk6qujx+uO78lV2nKqC EnGbeIRYKTOiq2Xl97ojCJ0BR/zhafIFna00m2NY7pT4nGFry/kJbJ7WFJGOO9c8bbY+ xXryvYWSfN1su6RPeFOJ8WoDpw2xTJ4nDqQOx6ujANg36mYwsax0TlrAzmnbghDfm1R7 YCM0rQP+2J9G8YlQllRxf5u0qrZLW58u+ZlSkQ0MxDL1kODnVAoz3fgg/Rrc5vAc9ld4 zEZA== X-Gm-Message-State: AOAM530NudQ65uYwd1D/UTre4ev/qa9Xdtc6KbI2d/GB+e2uASYTfRy6 c909eoazJDQK6zIs9FlORRGteust6sw= X-Google-Smtp-Source: ABdhPJy016qykM4zKN9Qi6JfK3qVDPwP9o/T39Ms+MDkUkUfokzes1Qf5zLlxXbld2c1dZQT0uzWYA== X-Received: by 2002:a1c:4e0e:: with SMTP id g14mr19484034wmh.160.1615692243866; Sat, 13 Mar 2021 19:24:03 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id e1sm14922249wrd.44.2021.03.13.19.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 19:24:03 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 8/8] tools/virtiofsd: Replacing malloc-like calls with GLib's variants Date: Sun, 14 Mar 2021 05:23:24 +0200 Message-Id: <20210314032324.45142-9-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210314032324.45142-1-ma.mandourr@gmail.com> References: <20210314032324.45142-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=ma.mandourr@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mahmoud Mandour , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Changed calls to malloc(), calloc(), and realloc() with their equivalent allocation functions in GLib, and replaced their respective free() calls with g_free(). Allocation and deallocation of fuse_req structs, fuse_pollhandle structs, fuse_session structs and many local variables are now established through GLib's functions. Signed-off-by: Mahmoud Mandour --- tools/virtiofsd/fuse_lowlevel.c | 30 ++++++++++++++-------------- tools/virtiofsd/fuse_virtio.c | 34 ++++++++++++++++---------------- tools/virtiofsd/passthrough_ll.c | 32 +++++++++++++++--------------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c index 1aa26c6333..5e188f8d8f 100644 --- a/tools/virtiofsd/fuse_lowlevel.c +++ b/tools/virtiofsd/fuse_lowlevel.c @@ -106,7 +106,7 @@ static void list_add_req(struct fuse_req *req, struct fuse_req *next) static void destroy_req(fuse_req_t req) { pthread_mutex_destroy(&req->lock); - free(req); + g_free(req); } void fuse_free_req(fuse_req_t req) @@ -130,7 +130,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_session *se) { struct fuse_req *req; - req = (struct fuse_req *)calloc(1, sizeof(struct fuse_req)); + req = g_try_new(struct fuse_req, 1); if (req == NULL) { fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate request\n"); } else { @@ -219,7 +219,7 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count) int res; struct iovec *padded_iov; - padded_iov = malloc((count + 1) * sizeof(struct iovec)); + padded_iov = g_try_new(struct iovec, count + 1); if (padded_iov == NULL) { return fuse_reply_err(req, ENOMEM); } @@ -228,7 +228,7 @@ int fuse_reply_iov(fuse_req_t req, const struct iovec *iov, int count) count++; res = send_reply_iov(req, 0, padded_iov, count); - free(padded_iov); + g_free(padded_iov); return res; } @@ -568,7 +568,7 @@ static struct fuse_ioctl_iovec *fuse_ioctl_iovec_copy(const struct iovec *iov, struct fuse_ioctl_iovec *fiov; size_t i; - fiov = malloc(sizeof(fiov[0]) * count); + fiov = g_try_new(struct fuse_ioctl_iovec, count); if (!fiov) { return NULL; } @@ -629,8 +629,8 @@ int fuse_reply_ioctl_retry(fuse_req_t req, const struct iovec *in_iov, res = send_reply_iov(req, 0, iov, count); out: - free(in_fiov); - free(out_fiov); + g_free(in_fiov); + g_free(out_fiov); return res; @@ -667,7 +667,7 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, struct fuse_ioctl_out arg; int res; - padded_iov = malloc((count + 2) * sizeof(struct iovec)); + padded_iov = g_try_new(struct iovec, count + 2); if (padded_iov == NULL) { return fuse_reply_err(req, ENOMEM); } @@ -680,7 +680,7 @@ int fuse_reply_ioctl_iov(fuse_req_t req, int result, const struct iovec *iov, memcpy(&padded_iov[2], iov, count * sizeof(struct iovec)); res = send_reply_iov(req, 0, padded_iov, count + 2); - free(padded_iov); + g_free(padded_iov); return res; } @@ -1684,7 +1684,7 @@ static struct fuse_req *check_interrupt(struct fuse_session *se, if (curr->u.i.unique == req->unique) { req->interrupted = 1; list_del_req(curr); - free(curr); + g_free(curr); return NULL; } } @@ -1760,7 +1760,7 @@ static void do_ioctl(fuse_req_t req, fuse_ino_t nodeid, void fuse_pollhandle_destroy(struct fuse_pollhandle *ph) { - free(ph); + g_free(ph); } static void do_poll(fuse_req_t req, fuse_ino_t nodeid, @@ -1783,7 +1783,7 @@ static void do_poll(fuse_req_t req, fuse_ino_t nodeid, struct fuse_pollhandle *ph = NULL; if (arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) { - ph = malloc(sizeof(struct fuse_pollhandle)); + ph = g_try_new(struct fuse_pollhandle, 1); if (ph == NULL) { fuse_reply_err(req, ENOMEM); return; @@ -2476,7 +2476,7 @@ void fuse_session_destroy(struct fuse_session *se) free(se->vu_socket_path); se->vu_socket_path = NULL; - free(se); + g_free(se); } @@ -2499,7 +2499,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args, return NULL; } - se = (struct fuse_session *)calloc(1, sizeof(struct fuse_session)); + se = g_try_new0(struct fuse_session, 1); if (se == NULL) { fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate fuse object\n"); goto out1; @@ -2559,7 +2559,7 @@ struct fuse_session *fuse_session_new(struct fuse_args *args, out4: fuse_opt_free_args(args); out2: - free(se); + g_free(se); out1: return NULL; } diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c index 523ee64fb7..598c97db1f 100644 --- a/tools/virtiofsd/fuse_virtio.c +++ b/tools/virtiofsd/fuse_virtio.c @@ -347,7 +347,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, * Build a copy of the the in_sg iov so we can skip bits in it, * including changing the offsets */ - struct iovec *in_sg_cpy = calloc(sizeof(struct iovec), in_num); + struct iovec *in_sg_cpy = g_try_new0(struct iovec, in_num); assert(in_sg_cpy); memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num); /* These get updated as we skip */ @@ -386,7 +386,7 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, ret = errno; fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=%zd\n", __func__, len); - free(in_sg_cpy); + g_free(in_sg_cpy); goto err; } fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__, @@ -410,13 +410,13 @@ int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch, if (ret != len) { fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__); ret = EIO; - free(in_sg_cpy); + g_free(in_sg_cpy); goto err; } in_sg_left -= ret; len -= ret; } while (in_sg_left); - free(in_sg_cpy); + g_free(in_sg_cpy); /* Need to fix out->len on EOF */ if (len) { @@ -476,7 +476,7 @@ static void fv_queue_worker(gpointer data, gpointer user_data) * They're spread over multiple descriptors in a scatter/gather set * and we can't trust the guest to keep them still; so copy in/out. */ - fbuf.mem = malloc(se->bufsize); + fbuf.mem = g_try_malloc(se->bufsize); assert(fbuf.mem); fuse_mutex_init(&req->ch.lock); @@ -528,10 +528,10 @@ static void fv_queue_worker(gpointer data, gpointer user_data) fbuf.size = out_sg[0].iov_len + out_sg[1].iov_len; /* Allocate the bufv, with space for the rest of the iov */ - pbufv = malloc(sizeof(struct fuse_bufvec) + + pbufv = g_try_malloc(sizeof(struct fuse_bufvec) + sizeof(struct fuse_buf) * (out_num - 2)); if (!pbufv) { - fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n", + fuse_log(FUSE_LOG_ERR, "%s: pbufv g_try_malloc failed\n", __func__); goto out; } @@ -573,7 +573,7 @@ static void fv_queue_worker(gpointer data, gpointer user_data) out: if (allocated_bufv) { - free(pbufv); + g_free(pbufv); } /* If the request has no reply, still recycle the virtqueue element */ @@ -592,8 +592,8 @@ out: } pthread_mutex_destroy(&req->ch.lock); - free(fbuf.mem); - free(req); + g_free(fbuf.mem); + g_free(req); } /* Thread function for individual queues, created when a queue is 'started' */ @@ -733,7 +733,7 @@ static void fv_queue_cleanup_thread(struct fv_VuDev *vud, int qidx) pthread_mutex_destroy(&ourqi->vq_lock); close(ourqi->kill_fd); ourqi->kick_fd = -1; - free(vud->qi[qidx]); + g_free(vud->qi[qidx]); vud->qi[qidx] = NULL; } @@ -764,14 +764,14 @@ static void fv_queue_set_started(VuDev *dev, int qidx, bool started) if (started) { /* Fire up a thread to watch this queue */ if (qidx >= vud->nqueues) { - vud->qi = realloc(vud->qi, (qidx + 1) * sizeof(vud->qi[0])); + vud->qi = g_try_realloc_n(vud->qi, (qidx + 1), sizeof(vud->qi[0])); assert(vud->qi); memset(vud->qi + vud->nqueues, 0, sizeof(vud->qi[0]) * (1 + (qidx - vud->nqueues))); vud->nqueues = qidx + 1; } if (!vud->qi[qidx]) { - vud->qi[qidx] = calloc(sizeof(struct fv_QueueInfo), 1); + vud->qi[qidx] = g_try_new0(struct fv_QueueInfo, 1); assert(vud->qi[qidx]); vud->qi[qidx]->virtio_dev = vud; vud->qi[qidx]->qidx = qidx; @@ -1032,9 +1032,9 @@ int virtio_session_mount(struct fuse_session *se) __func__); /* TODO: Some cleanup/deallocation! */ - se->virtio_dev = calloc(sizeof(struct fv_VuDev), 1); + se->virtio_dev = g_try_new0(struct fv_VuDev, 1); if (!se->virtio_dev) { - fuse_log(FUSE_LOG_ERR, "%s: virtio_dev calloc failed\n", __func__); + fuse_log(FUSE_LOG_ERR, "%s: virtio_dev g_try_new0 failed\n", __func__); close(data_sock); return -1; } @@ -1059,8 +1059,8 @@ void virtio_session_close(struct fuse_session *se) return; } - free(se->virtio_dev->qi); + g_free(se->virtio_dev->qi); pthread_rwlock_destroy(&se->virtio_dev->vu_dispatch_rwlock); - free(se->virtio_dev); + g_free(se->virtio_dev); se->virtio_dev = NULL; } diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c index fc7e1b1e8e..5c475a30af 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -399,7 +399,7 @@ static void lo_map_init(struct lo_map *map) static void lo_map_destroy(struct lo_map *map) { - free(map->elems); + g_free(map->elems); } static int lo_map_grow(struct lo_map *map, size_t new_nelems) @@ -411,7 +411,7 @@ static int lo_map_grow(struct lo_map *map, size_t new_nelems) return 1; } - new_elems = realloc(map->elems, sizeof(map->elems[0]) * new_nelems); + new_elems = g_realloc_n(map->elems, new_nelems, sizeof(map->elems[0])); if (!new_elems) { return 0; } @@ -549,7 +549,7 @@ static void lo_inode_put(struct lo_data *lo, struct lo_inode **inodep) if (g_atomic_int_dec_and_test(&inode->refcount)) { close(inode->fd); - free(inode); + g_free(inode); } } @@ -904,7 +904,7 @@ static void posix_locks_value_destroy(gpointer data) * closing this fd should release all OFD locks. */ close(plock->fd); - free(plock); + g_free(plock); } static int do_statx(struct lo_data *lo, int dirfd, const char *pathname, @@ -1020,7 +1020,7 @@ static int lo_do_lookup(fuse_req_t req, fuse_ino_t parent, const char *name, if (inode) { close(newfd); } else { - inode = calloc(1, sizeof(struct lo_inode)); + inode = g_try_new0(struct lo_inode, 1); if (!inode) { goto out_err; } @@ -1532,7 +1532,7 @@ static void lo_dirp_put(struct lo_dirp **dp) if (g_atomic_int_dec_and_test(&d->refcount)) { closedir(d->dp); - free(d); + g_free(d); } } @@ -1564,7 +1564,7 @@ static void lo_opendir(fuse_req_t req, fuse_ino_t ino, int fd; ssize_t fh; - d = calloc(1, sizeof(struct lo_dirp)); + d = g_try_new0(struct lo_dirp, 1); if (d == NULL) { goto out_err; } @@ -1606,7 +1606,7 @@ out_err: } else if (fd != -1) { close(fd); } - free(d); + g_free(d); } fuse_reply_err(req, error); } @@ -1633,7 +1633,7 @@ static void lo_do_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, } err = ENOMEM; - buf = calloc(1, size); + buf = g_try_malloc0(size); if (!buf) { goto error; } @@ -1719,7 +1719,7 @@ error: } else { fuse_reply_buf(req, buf, size - rem); } - free(buf); + g_free(buf); } static void lo_readdir(fuse_req_t req, fuse_ino_t ino, size_t size, @@ -1943,7 +1943,7 @@ static struct lo_inode_plock *lookup_create_plock_ctx(struct lo_data *lo, return plock; } - plock = malloc(sizeof(struct lo_inode_plock)); + plock = g_try_new(struct lo_inode_plock, 1); if (!plock) { *err = ENOMEM; return NULL; @@ -1954,7 +1954,7 @@ static struct lo_inode_plock *lookup_create_plock_ctx(struct lo_data *lo, fd = lo_inode_open(lo, inode, O_RDWR); if (fd < 0) { *err = -fd; - free(plock); + g_free(plock); return NULL; } @@ -2731,7 +2731,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, ino, name, size); if (size) { - value = malloc(size); + value = g_try_malloc(size); if (!value) { goto out_err; } @@ -2770,7 +2770,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, fuse_reply_xattr(req, ret); } out_free: - free(value); + g_free(value); if (fd >= 0) { close(fd); @@ -2812,7 +2812,7 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) size); if (size) { - value = malloc(size); + value = g_try_malloc(size); if (!value) { goto out_err; } @@ -2897,7 +2897,7 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) fuse_reply_xattr(req, ret); } out_free: - free(value); + g_free(value); if (fd >= 0) { close(fd);