From patchwork Sat Mar 13 16:36:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452492 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Jj0Ws3Zm; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DySzt0gRLz9sRR for ; Sun, 14 Mar 2021 03:38:34 +1100 (AEDT) Received: from localhost ([::1]:53506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7Hc-0002Dc-1r for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:38:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7Gz-0002Bg-7l for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:37:53 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:45302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7Gx-00078t-D0 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:37:53 -0500 Received: by mail-wr1-x435.google.com with SMTP id e10so6433813wro.12 for ; Sat, 13 Mar 2021 08:37:50 -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=Jj0Ws3ZmjTnUnaoS6kEuwxVtN7cLiHKUISvPltNZfERuZKsC1f6MKe7fcH2fU8nDiR o67/SsykaPONvIRs2CGD6GEAPxqaLQ4KUUzlwCv+QrEGSPYTqrZxRKajMjh3WisDcAaN FyGB/+R30NL/3nQ7c1zn/Eb22CR1CMaqOqYbVji6SkBrs/HvZlAqOCUbmuz7VsbWqBKZ aFn7p3wU1HqvEkiIhggKYjseX7OFWaLPBJG3RZSrSfL8EUiFGrNyd2W+JNDKef/qcOvC QSyk94OERGbnBAKPye6LHYeyr2R8boPo4ZYAhqV2voQbl2hV+fWq4q8kxmAunj1lKzxb Hx+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=2rnIQur47bUqEW0oQ7uZPNdfpmlBj++ZpXvn5yiPVOw=; b=Tk9nOiYXkdy7jdHZE/7HAcG4aVJ1QgDCK6mnmqDyoTsHRrBQtVAA4yKRGOluyUVlAy rDy3PsC7e9nwftDjwNlsVYtHjji06Dq4q5EX+ykALviA+s/vIRj0S88PK24dVuIrORkE B3PKfoTapEdi5FEu/V/osaon/T3VHoRI216/NLaxC9052vssaoJawc3iergEg+ieCsDA 39tnpqZvcq5gBel2BOS945P4TwW+kYaoYNphebqth3IlIvhHlBIQAsloPQ1/oQJUYu57 ZG2L0v571uaHt/i1BBXrD0c6WV9v8u3pnkACDx2wx/WAkfnF7xWbwwEzii7XPQzaU8px 6Wjw== X-Gm-Message-State: AOAM530izBPxnmugRHVOndhCVP64Tp9h0I6qMmGDiIjlg6Obu6C/elXO 9mPjBMHLBS4ipI4eBOUc6lqWo0eLd/A= X-Google-Smtp-Source: ABdhPJwTOjWprdyD+7yxQjG1OA2o4z1dtWCQTMx6G/tsgRlgD48Fmz6LJWqYveYW76e1RZN10gegUg== X-Received: by 2002:a5d:5051:: with SMTP id h17mr19253455wrt.80.1615653469668; Sat, 13 Mar 2021 08:37:49 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.37.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:37:49 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 1/9] bsd-user/elfload.c: Replaced calls to malloc/free with GLib variants Date: Sat, 13 Mar 2021 18:36:45 +0200 Message-Id: <20210313163653.37089-2-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x435.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+incoming=patchwork.ozlabs.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 Sat Mar 13 16:36:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Vne8VT16; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyT261BVJz9sW4 for ; Sun, 14 Mar 2021 03:40:30 +1100 (AEDT) Received: from localhost ([::1]:57784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7JU-0004CU-6B for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:40:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HL-0002Rv-Q6 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:15 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:33071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HD-0007Ih-Hl for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:15 -0500 Received: by mail-wr1-x435.google.com with SMTP id 7so6456525wrz.0 for ; Sat, 13 Mar 2021 08:38:07 -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=iHt/kKgnn7OMCOswaApfoEE2IOMfcSBQxaUlkBfROq4=; b=Vne8VT16lc9LjWIxaeOA3fR2gy71F5DGrOOQ+Q31uW9CAZlcR2KEVICOD9c9/EpWb5 wcbZvObaimEtKvz4YnwXnMjAoGWF3XLDY31jIaZn7DABothdzMSCNaD6KRJoUPWXT5/0 OfYzUSix8zzbuXB6wblCPMp6tYjG8gd9SlOdLtXP+57UlI6tw77rAwX57RIFyDawXoa2 UqgyZC26WbW8lZqCWIGgknQW+6VWiqWW2X2MJSGIXuHwAyD8IHdTK4fWkZBp34fp/+yx fOVLihIXf4xrx2S4yVTCssewjRkadsObZ2Evusd9CxRutXqwksRr4B1PJVwaG+ESENW4 Yvcg== 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=iHt/kKgnn7OMCOswaApfoEE2IOMfcSBQxaUlkBfROq4=; b=f7tkHrApa4ZZbNRAsc/uhwDYMYNiDefW4ySpj6FbYD3VNX4TKsLpRJw+RkSepkwoSS tNZLZVMeA68dgyGkX3O6PRAAnDSc9HNsBv2Ep3l0XxNZnaIXHi40Y/2Iz5D3JyuIMLJA j9Re/BYtcjWG7YJSucPqhDcpS0OTYX6CQPgD3ttwb2B3kDYkkQxRqkMpY+gvGELl5sFd BEm64gHKY3XKDbOetfirTy2+CymlFgC+k+dk6A4iyCPsfegMYeCHFLjEOpuh31pnqCCh xEiB7XcXEbZFJWYsVV5uChzMqFHqRIP7IbfDh024JA1r+3ujYV27Df3wKt2Prr6wZvOt 8+Dw== X-Gm-Message-State: AOAM533kILOAQwm3Vj6nvn7QBqBaVPCf96VK+oHwAQwV1Y1rGGSqIk9j yyXs9wfdnoZKGcOxIEYJhEqomxpeRlo= X-Google-Smtp-Source: ABdhPJw0wsi7z9utCj2pHYGtpprrXk770490KvyQHEbDjtrUDa7pnkLacfKcW9Gqa4KVDx491xDE7w== X-Received: by 2002:a05:6000:245:: with SMTP id m5mr20050311wrz.284.1615653486101; Sat, 13 Mar 2021 08:38:06 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:05 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 2/9] hw/audio/fmopl.c: Fixing some style errors. Date: Sat, 13 Mar 2021 18:36:46 +0200 Message-Id: <20210313163653.37089-3-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x435.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+incoming=patchwork.ozlabs.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 | 52 ++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c index 8a71a569fa..45f15c53b3 100644 --- a/hw/audio/fmopl.c +++ b/hw/audio/fmopl.c @@ -607,26 +607,26 @@ 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; - } + 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; + } ENV_CURVE = g_new(int32_t, 2 * EG_ENT + 1); /* make total level table */ for (t = 0;t < EG_ENT-1 ;t++){ @@ -696,10 +696,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 +1082,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 +1128,7 @@ void OPLDestroy(FM_OPL *OPL) } #endif OPL_UnLockTable(); - free(OPL); + free(OPL); } /* ---------- Option handlers ---------- */ From patchwork Sat Mar 13 16:36:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452497 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cijuSOkW; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyT3x1GSrz9sRR for ; Sun, 14 Mar 2021 03:42:05 +1100 (AEDT) Received: from localhost ([::1]:60780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7L1-0005Zx-68 for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:42:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HO-0002VJ-EK for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:18 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:34289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HF-0007JR-P5 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:18 -0500 Received: by mail-wr1-x430.google.com with SMTP id u16so6454634wrt.1 for ; Sat, 13 Mar 2021 08:38:08 -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=sg5nGgHTBeRiuxmxPZ+wz0jzsIryQrfg1B3YEn8ftJE=; b=cijuSOkWAzwILU47Vh5JZytpuGwr7ZsuvuWaxYYuhgkonXx4tjW1oWQfxiwzPFiiDm sxTe1GP8tmcwBlY/1mEseh4bSSNF46AVbQ+ENzGAzPO2nlEU8h9ggYNmDTYsZ+isdrHs tZ7U4nfveu/2pL/sJldqDQYaGyYDU47yvJ6yAlhOvu5t++8YbxfwYXoKd5NWeGrbuss/ UIzjPWkDPjzIBfxnFs7nnXL1y4Trtfa+fBi9dlVAfCQJXBOYQKzQlVea3mYyiIKNx4D5 TSbYdkk2BumSVFrDC0mz/yrzAX3enX2/1BHDo9yB3ZAdOVTUCVEkB6VaEhvgH6W88y/H m0Ww== 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=sg5nGgHTBeRiuxmxPZ+wz0jzsIryQrfg1B3YEn8ftJE=; b=EdzZVbg9OKxcPiEWcjHWEUP1ZHW5dYAPsjuvj52GpiquGIRDAUg/yo1U82JfpFeZ6i MQjxhK2PnNUDOTnJIm2ZJ5sm9lB6FmLO0clBg20Og/0dFmDy4tq7ryyfb8W1ZXpLqe2x Ei2VB6uNSejatsn7Fx5QaV4+f7DmwLNgCk0ZP6ssEt3e4MHTtKwbwo+McA8FMQcM2NTw +wl9Dtsr9iaHqRR7Khzgx0rhZeurrTHUBeXstcKLwteCLs4ljDRnHCS4/GyqiC9FFHxl WFFS65cIHrCMQ2qickqylGhs98LpXvy0buzpdwy3vW2efrWb2JklOmu0NHI8iM7WNMJb oZOA== X-Gm-Message-State: AOAM533G7wBOj1jlQTLV3SYW/Fiuy6m8YjavfZ8XJWyfwoqeqqNJz9Jm XFXLLCZV/Tkza3WyvBVyoy7MDaDwgq8= X-Google-Smtp-Source: ABdhPJzylw7DRrfpMzHvT6hJMZHrGRnd1AiKxGd4/BZSsbkx4kLBIl26mnsLFsHHKN+Kf597wmiO3g== X-Received: by 2002:adf:e411:: with SMTP id g17mr19514333wrm.225.1615653487177; Sat, 13 Mar 2021 08:38:07 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:06 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 3/9] hw/audio/fmopl.c: Replaced calls to malloc with GLib's variants Date: Sat, 13 Mar 2021 18:36:47 +0200 Message-Id: <20210313163653.37089-4-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x430.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+incoming=patchwork.ozlabs.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 | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c index 45f15c53b3..6cecf2b963 100644 --- a/hw/audio/fmopl.c +++ b/hw/audio/fmopl.c @@ -607,27 +607,34 @@ static int OPLOpenTable( void ) double pom; /* allocate dynamic tables */ - if((TL_TABLE = malloc(TL_MAX * 2 * sizeof(int32_t))) == NULL) + if((TL_TABLE = g_try_new(int32_t, TL_MAX * 2)) == NULL) return 0; - if((SIN_TABLE = malloc(SIN_ENT * 4 *sizeof(int32_t *))) == NULL) + if((SIN_TABLE = g_try_new(int32_t *, SIN_ENT * 4)) == NULL) { - free(TL_TABLE); + g_free(TL_TABLE); return 0; } - if((AMS_TABLE = malloc(AMS_ENT * 2 * sizeof(int32_t))) == NULL) + if((AMS_TABLE = g_try_new(int32_t, AMS_ENT * 2)) == NULL) { - free(TL_TABLE); - free(SIN_TABLE); + g_free(TL_TABLE); + g_free(SIN_TABLE); return 0; } - if((VIB_TABLE = malloc(VIB_ENT *2 * sizeof(int32_t))) == NULL) + if((VIB_TABLE = g_try_new(int32_t, VIB_ENT * 2)) == NULL) { - free(TL_TABLE); - free(SIN_TABLE); - free(AMS_TABLE); + g_free(TL_TABLE); + g_free(SIN_TABLE); + g_free(AMS_TABLE); + return 0; + } + if((ENV_CURVE = g_try_new(int32_t, 2 * EG_ENT + 1)) == 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 */ @@ -696,10 +703,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 */ @@ -1082,7 +1089,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); @@ -1128,7 +1135,7 @@ void OPLDestroy(FM_OPL *OPL) } #endif OPL_UnLockTable(); - free(OPL); + g_free(OPL); } /* ---------- Option handlers ---------- */ From patchwork Sat Mar 13 16:36:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452499 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=jPfH694K; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyT6y0c0nz9sRR for ; Sun, 14 Mar 2021 03:44:42 +1100 (AEDT) Received: from localhost ([::1]:38082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7NY-0007vp-4L for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:44:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HO-0002W2-VR; Sat, 13 Mar 2021 11:38:18 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:38791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HL-0007Ki-BD; Sat, 13 Mar 2021 11:38:18 -0500 Received: by mail-wr1-x434.google.com with SMTP id z2so3446404wrl.5; Sat, 13 Mar 2021 08:38:09 -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=SWr56kRSOwx9E4WVmBZO8tKFvHyaIRM7iDN7QdVhN0M=; b=jPfH694KCyCjIth3PR+wUrfs/TcMLA+8AIanuYJ/UoaBQbdMQsq0elAXtYE9oFjf+t hYNqE7FDQ1YAbO+3PXM/KUA1vfmpIp4NEu3CvPnBQMQhjqhY5K1R66+qXWuKzsFELoz9 L/a/xQRZHfb9NbqGJ2WroA7PtSSg2yUPJVGu7I4VCoEpZs9h60SCpg73PH3EWJJLiILV JTvdVj+yte3ATRLnze8ivy3+f8HDlPK48RKQpOgrgnq2+Pvk5SdGxN7pWrmu+M5A0zcN OASL4Yi+Mb8T7vp5vz/O+IInSGDCTkq+o786S7LGbrkfiaUhBmxrk/8YqdsSZTXR67Of Y4vw== 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=SWr56kRSOwx9E4WVmBZO8tKFvHyaIRM7iDN7QdVhN0M=; b=gB9dEvIkDFJoaCQ906q3YjM9K5F247xu5B0PEXs/tiFHrKUMqKRS4ZB9ApiWxPGpZq qrWmQlQomRr0iMUihuHOLRyKZcldNcUPUEOtuQKvLBTtLzyRaLdBdV1gpGmxaGawBgsP 1rD/rdopcfrEVdjOPyldE5AzIvveUEy3KrU/jMeFynvkhnOCR0lgyIXAjMK11gF3CqI+ AKc9HwRs0U69pbuEhHKvqCe0/XDKc4aj5UL3I4Ver7uczwr3udahhzorW3q0BlFbClF6 kpWEFah1Ev4LFh4EeXxmHy4ZIZJPQ/1A+XAKGKUup0U3GmQ1n0Xzd/EETIjBVsyRTs8s IZVg== X-Gm-Message-State: AOAM533l5ElXSQdKrDTSMZNaUHoEapR+FGaQhdkoN5HtXq8spu+xnCQR nbRuv2VjCU7TfDA5kGOlHDjura/CBhI= X-Google-Smtp-Source: ABdhPJxqhyViQNChPyViLihVE2NJZWTLFTqDZaFVMNd94ILueqa7sIVhyVYRZF8KkoimwB/X8RSidw== X-Received: by 2002:a05:6000:18a3:: with SMTP id b3mr19661574wri.373.1615653488562; Sat, 13 Mar 2021 08:38:08 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:08 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 4/9] pc-bios/s390-ccw/netmain.c: Changed a malloc/free to GLib's variants Date: Sat, 13 Mar 2021 18:36:48 +0200 Message-Id: <20210313163653.37089-5-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-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: "open list:S390-ccw boot" , Christian Borntraeger , Mahmoud Mandour , Cornelia Huck , Thomas Huth Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Changed a call to malloc() and its respective calls free() with GLib's allocation and deallocation functions. Signed-off-by: Mahmoud Mandour --- pc-bios/s390-ccw/netmain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index 056e93a818..7f78150144 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -243,7 +243,7 @@ static const char *get_uuid(void) int i, cc, chk = 0; static char uuid_str[37]; - mem = malloc(2 * PAGE_SIZE); + mem = g_try_malloc(2 * PAGE_SIZE); if (!mem) { puts("Out of memory ... can not get UUID."); return NULL; @@ -261,7 +261,7 @@ static const char *get_uuid(void) : "d" (r0), "d" (r1), [addr] "a" (buf) : "cc", "memory"); if (cc) { - free(mem); + g_free(mem); return NULL; } @@ -269,7 +269,7 @@ static const char *get_uuid(void) uuid[i] = buf[STSI322_VMDB_UUID_OFFSET + i]; chk |= uuid[i]; } - free(mem); + g_free(mem); if (!chk) { return NULL; } From patchwork Sat Mar 13 16:36:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452500 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=LnDcHhYm; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyTBg37hWz9sRR for ; Sun, 14 Mar 2021 03:47:55 +1100 (AEDT) Received: from localhost ([::1]:42122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7Qf-0001NP-Cs for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:47:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HP-0002Xg-Je for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:19 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:36547) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HL-0007LQ-Bw for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:19 -0500 Received: by mail-wr1-x436.google.com with SMTP id k8so3431877wrc.3 for ; Sat, 13 Mar 2021 08:38:10 -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=RSopiiERPyXXigW3qXTADJ0K0yxpsR5if3aqskRERRg=; b=LnDcHhYm3e/kumShnDHL1pbx1Nmtn05p8EQLhZuFuadrlQO15rjQ7IA84ZePhXdRYZ RYd7HRg5046sa8+RZtn4Z/uJdM95u+KXQ1FE3fkC9grjuxj8FQxvFwEKqPhx8TP/GB53 xTgAVFIQ0Z7o40vRYw7E7hxZn0Z0IlL/wruBp8qbhkHAbMA5t3St1rEwbsL1tWFec1oX BZ+GzpN8I+dVB4iOgYBDRaoan84JZuxaVHTYBKzk87O+u+p+KVXjjGSATDImJmcBvVef LzIkJfYGU9ivAz+U+cWC0+qd5jAhzxzOcTZ4DKUBhiEORE3fdD6NGmE/ZagU+iT/kdvG eAlg== 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=RSopiiERPyXXigW3qXTADJ0K0yxpsR5if3aqskRERRg=; b=L+Skrd0Q1/kk/RGAzuL8XGOP2QgmDgp3sHS1iUJ6b9yu/vc0ZipK21IpFCwr1uivTB Jlk6+MnmXXPDz8rdjv2+1v0JC3yAO7430uYqwwuC7VzKtw+rvn1t7kFKY/txyUlFweS3 Ql+X2q1g7eoIUIaRBpfwSMFXlSLROlrcWS8f6hxrVl4p9GeCbA+mB6b8s5ysPePcrwXL M0HmEVa+/ZXhNzvmzZiEqmb877htoyrUwtcOVYpmn/9qeEJsh/4ksqk9Q3wEYpfK+O8p 6Wvfj3ZQyk0oqTdZCmi5rKaXrgLCOfO4Qh5kgzzM5ks1psj2GUGoCahkOODhjZYs7Y89 6ReA== X-Gm-Message-State: AOAM532AAKU08eNT3i31X4k3DuE9beYc3MMWRyRbC846Qhkfkli4l+6J O7KuyyRExrtKq2033ONKsP1cV7TYitg= X-Google-Smtp-Source: ABdhPJyIFn891eaULzGGJKxnofPTElp61mUV3zGowXMCIWbydAq8HRk99aeFSzJ0c5zvNB+MZJttkA== X-Received: by 2002:a5d:6205:: with SMTP id y5mr19436499wru.238.1615653489712; Sat, 13 Mar 2021 08:38:09 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:09 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 5/9] target/xtensa: Replaced malloc/free with GLib's variants. Date: Sat, 13 Mar 2021 18:36:49 +0200 Message-Id: <20210313163653.37089-6-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x436.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Replaced the calls to malloc() and their respective calls to free() with GLib's allocation and deallocation functions. Signed-off-by: Mahmoud Mandour --- target/xtensa/xtensa-isa.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/target/xtensa/xtensa-isa.c b/target/xtensa/xtensa-isa.c index 630b4f9da1..d4f742a67c 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++) { @@ -333,33 +333,33 @@ void xtensa_isa_free(xtensa_isa isa) */ if (intisa->opname_lookup_table) { - free(intisa->opname_lookup_table); + g_free(intisa->opname_lookup_table); intisa->opname_lookup_table = 0; } if (intisa->state_lookup_table) { - free(intisa->state_lookup_table); + g_free(intisa->state_lookup_table); intisa->state_lookup_table = 0; } if (intisa->sysreg_lookup_table) { - free(intisa->sysreg_lookup_table); + g_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]); + g_free(intisa->sysreg_table[n]); intisa->sysreg_table[n] = 0; } } if (intisa->interface_lookup_table) { - free(intisa->interface_lookup_table); + g_free(intisa->interface_lookup_table); intisa->interface_lookup_table = 0; } if (intisa->funcUnit_lookup_table) { - free(intisa->funcUnit_lookup_table); + g_free(intisa->funcUnit_lookup_table); intisa->funcUnit_lookup_table = 0; } } From patchwork Sat Mar 13 16:36:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452496 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gbKA6+8J; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyT3b37Yfz9sW4 for ; Sun, 14 Mar 2021 03:41:47 +1100 (AEDT) Received: from localhost ([::1]:59972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7Kj-0005EO-66 for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:41:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HO-0002UY-0K for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:18 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:45750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HL-0007Lp-Go for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:17 -0500 Received: by mail-wr1-x431.google.com with SMTP id 61so3438490wrm.12 for ; Sat, 13 Mar 2021 08:38:11 -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=MhHnkYeqj2bHe1c8USts/NrhTNQ41OZC2qSF3HkSwjo=; b=gbKA6+8JyCYu8DDvvsrx2TYXBlkYr/6SjwzY3o7LZlzDGOYmwBrpoQoHC7U9c9TVBD 9DxF8ELBeUyJlnIOM9Vsc2CrCKNH7qxmwWQ3Cm4YeOME4+eG+hF9onldEj5T8ZDc3hKk KEFoev3iinspRJJUVufVgpCM4DM7agSi+6PO8v9YXqOE4t63itbArAYfkGLxtF6Q3BnG CJcc8GRLuapNJk49A3pgUgXFR7nrvqCiqeyEYB2EA7l1yVBIF/+/KwEFbKwlQQUCZiMz vuSgTBTUrTiMFpVIPwLm/dNNesT1AYru8w9kLuY2jzp1+ji8/aKK5IkGtqviRvic3oR+ sPsQ== 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=MhHnkYeqj2bHe1c8USts/NrhTNQ41OZC2qSF3HkSwjo=; b=dKIcAw9RcZcIEBpo9ENx+VxT71B6PfaoCPKrdxC2kqDJ9PFkCAcpi4o34SWsrsgFpI HnebMCXiJX5NzZtdoB1+xYdWhN/zkrJbxZeZy39MJEcFlqLAnyZJ0b301lTax7ClSp+g 18+CB1awqLu28elKpDM2gZXqywf9bMYhMD1MaACh2weH6MuJQHN8WcDpSodfSvqjaTOi ZZUzHO20lBek/jtjg9LehoXlWsjC/ifUf/OGCK58WmQMONn7N13MUzlkKcgBeN5t2/AG nNOEwfEGEmvbK9YE2N8cHMVcK3B7fd4MjVQeKfUqSA6fLI5GJ5l1lxsgrndpT2AQtA5R dTTg== X-Gm-Message-State: AOAM530japHcDePCoFq1up7YvM5krqa3jYzcn6P5zr4IxKCY1gyEKyAn 5nyR4vu7CCmDhBnwVVy8YH1M64XMR8o= X-Google-Smtp-Source: ABdhPJx2/KcLEN1cRlf5tGzxii0Mv/PpIs4ZxOmfMt1dLE1+w64LvzuVYJaRXuaRiSOWmw1CXddKzA== X-Received: by 2002:a5d:5141:: with SMTP id u1mr19719132wrt.31.1615653490693; Sat, 13 Mar 2021 08:38:10 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:10 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 6/9] util/compatfd.c: Replaced a malloc with GLib's g_try_malloc Date: Sat, 13 Mar 2021 18:36:50 +0200 Message-Id: <20210313163653.37089-7-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-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 Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 errors using the checkpatch.pl script. 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 Sat Mar 13 16:36:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452498 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=LsdbMdYN; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyT5J5F0vz9sRR for ; Sun, 14 Mar 2021 03:43:14 +1100 (AEDT) Received: from localhost ([::1]:35984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7M7-00073F-NH for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:43:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HO-0002Vt-R1 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:18 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:34790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HL-0007MU-H0 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:18 -0500 Received: by mail-wr1-x433.google.com with SMTP id j7so3438011wrd.1 for ; Sat, 13 Mar 2021 08:38:13 -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=LsdbMdYNFEnv732xQltVLIvXeLbi+qR+SFfK5oUMdhpXbB0gXi63Vzdx3Cs4d+1gsM 4KmCZcQyNZX+ZVXGBUt/SUue21YQOY1SGzgaY8mI/Ixk23baL//MwII/fU+x8pasuJZ3 M5/8z9f3OV1XYwZ/LM48XTebmlNnZ+cRxXKOwqDbsvLqgJQvRMNtpRmK/hSNLzPzwKAD 8yZXdIABfJItDx5OiZuas9xg9YOfyG3I0E8OmTF2C/qq9N5czk97Yl2KviwZIdRL8qMQ 6R9vss4IIbAmCVhug0Iv9mskR3ejC5CywRGjSHJCEdjQSPUIXuHEHn1yBwjiL3lLXsgP AfyQ== 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=n73sXAneFpitANjfBs12CthDW+DoEfowtybXbR4dO7lgyYiO4jo3GtoguWb6NHEeVf OBNBGLOnBwnt9Mkobg0nI4bxUVBvYPC+NyrLKfDLLr5Q65P2JB+rFUnCAgMBMbfOxPYf 9qKpbh676azcoCfgedoQ3/qSa8JGvsgeHUrD7y2aQyxOulKm1gJHdKDlzgmmWmVx8eZ5 wVPWt5mYjxEXTxBOw/8/yy6fF6J6Q82G9F4VVOWjAHVPdAUf5LIwITYBol451lzZWi7C ByOhYWhOZb/QAw1VxOR1imuOBMBEJJyKIf5uAqhIIvOfCpyofXwPevimFpKBmV4Rp7Vc J2DQ== X-Gm-Message-State: AOAM531fx83JIowYKnXL+TYdRJs0sKfIJYvTKfJsT7p1JQ54hjily4kf U09HeVQXoEfgQOn4NolR7yxNwHGg35s= X-Google-Smtp-Source: ABdhPJz9Tc/gsFq+AKRp1HYIUnmFnrTJ7b9oW7KhYcmGBewdl6xWeSnevORhsi5s0aYZ+RjfOIhttA== X-Received: by 2002:adf:ecca:: with SMTP id s10mr18803479wro.324.1615653491884; Sat, 13 Mar 2021 08:38:11 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:11 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 7/9] tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0 Date: Sat, 13 Mar 2021 18:36:51 +0200 Message-Id: <20210313163653.37089-8-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x433.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+incoming=patchwork.ozlabs.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 --- 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 Sat Mar 13 16:36:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=See2a8S1; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyT0n4r1Vz9sRR for ; Sun, 14 Mar 2021 03:39:21 +1100 (AEDT) Received: from localhost ([::1]:54100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7IN-0002Vw-KX for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:39:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HN-0002Tk-LT for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:17 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:52107) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HL-0007Ma-H9 for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:17 -0500 Received: by mail-wm1-x32e.google.com with SMTP id l19so5558357wmh.1 for ; Sat, 13 Mar 2021 08:38:14 -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=See2a8S1wnQTu12mCkpQ21/eYHwq7+7WZqBcBCOxcr4nTogG9QCrrO1Am3Q90nwXXL D3Xh798YuGxTIG4FbdyFVvp14I4nZEDPNVFUu/jYPe9bSxI+8dCl5YKMDQYoTw8AdbGa 4JPgUnV7Kl6cGH1jANAogV+eX6pkGhyL7UbCBUGBhLDEi3tn7EY47uKlqf3zCeyV9NmG WE+29xhhyXHCJ3tmkrnDDwnlFh/PxIbQKIabpsYJ7j8qbfCd6ZZvynk1LrcNCOcwIGBF mR38mRr+zd3tmw1h9lJ5JHwSusKFTRnPBAMynsdafAMJNj+V2wENNKE+a2t5cvkgyfzj l1AQ== 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=XeR5gjmsOZWDTXMSFcyFE+nvRZgzqSwFcv+ZQt5ldR0yAnx6Olgb88M5rSSqi31CBm bqjTiMXQClFHiTs7xur+Y4vSIDnREdN+IKJJhF+AnBV/KzaRWkGJYuPYamprHLiMMDw6 AMYFnBCFrpPjKQ4ubPKwweBB4vryFQmvJIgCQHTftAmw2cJuSKE0/FyI1KDHH+hSKM0E R+LZGcsiqu1Cgaw98Hv1q7tOEZUP8MJf2esGBf17Dm/fYMzM0tsJDXWk6K45geoemXXK 8Ng9eDOO74OziZAG/0139pb1djVM1KjsUYTYVbkiGHDYjAdhPtbg8nFS3JgUoOJ0E/4j 3HgA== X-Gm-Message-State: AOAM533/ueNtDO0J+A1E17tD9yxF6JqDlgNymW0Bgp1jzVpnGKIjROrW tVJAaWlBxJtmrqXrAVaa8v/eNtPJ8rY= X-Google-Smtp-Source: ABdhPJx4zyOgQlp7udBSXkPrs4mYz0mckWfKPf78h+Ua4fk5s7N/3rrrFcRIeLvp1jOfhAMDDP2vLQ== X-Received: by 2002:a7b:c5c7:: with SMTP id n7mr18257469wmk.63.1615653493064; Sat, 13 Mar 2021 08:38:13 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:12 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 8/9] tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc Date: Sat, 13 Mar 2021 18:36:52 +0200 Message-Id: <20210313163653.37089-9-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-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 , "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 --- 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 Sat Mar 13 16:36:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahmoud Abumandour X-Patchwork-Id: 1452508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=LRVezUWw; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4DyTCW5P62z9sRR for ; Sun, 14 Mar 2021 03:48:39 +1100 (AEDT) Received: from localhost ([::1]:44056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7RN-0002Cq-Or for incoming@patchwork.ozlabs.org; Sat, 13 Mar 2021 11:48:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lL7HR-0002cw-Ti for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:21 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:44163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lL7HN-0007NW-BT for qemu-devel@nongnu.org; Sat, 13 Mar 2021 11:38:21 -0500 Received: by mail-wr1-x42b.google.com with SMTP id o14so2647721wrm.11 for ; Sat, 13 Mar 2021 08:38:16 -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=LRVezUWwkD//9War1RbONH8jWzRpq2xti47gZZX1R26CxwHolq8xlM9v6Jbt/2J2uI 8nSFTFGtmcdLlgFkh5cakh5qqnRTl+wWQwfYUkqxqKlBkgXgZgsKs65D/dfp3R+UDSsL rbmCLbONtmtDzeqiCTF6RFgtZOVxIXEpaSoeBr+whP+vjfD5hGixz+snsLPGxEJ8PLxo U1TLvPGd4nDZikY2sv/C6L++PS7TIwhfFMFNjXvSP7+aeRhC/ev+Tr596K0mIz3zrqya MAKvbKR5jSs6pFOa58TXPKP9Nznlo6Y0ZZi3NaNOcFGZP0LZyYWC41ECdtt8olsRljC7 GZcw== 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=G+gxSYMpvmuCns67iYitkr4wl58J8IwFgZnpWr3kTBhbwpNdHKNWchrYIQwNtXRALV eZoMjhxJIm2BPbVl9tR7KNcfMbTTS9b8m9NmomkRDEJFVZBzvVzoM0HxKpobEVi+iy00 rR+4KNRMCJfoO0LXHEu5b+x8rCbxvmPs6AcYThdX/OlP7sIG/NGkgQm3dQU2wfcYfH2Q H7SMDoujk4d3y4dtOFmZa8cEYQCrSX8kOpGyFkko8a+RhWS5z1XNPlL3ePHeTHj8XbSF BYXWaYnyq3rbIe6y6HcIx4wSd13cwoAqVwB2v09mr4NBBcHO0AxmFhCTvH3jIOhm72QW BuXg== X-Gm-Message-State: AOAM532TMF7/AS5Kb9puHMrMGLbSoTC3uvqqzLHWS3U9s1wQPJNzcNK9 3qq8RFXf4eThsfJgWCQUh1+EYsN/guQ= X-Google-Smtp-Source: ABdhPJx5noi/B54EU76sZt0MYK0Zu1w6LhvOAtqG+DRe/kO7D6Q4PtxdIbbSony2EYOfLZcWHyl7kg== X-Received: by 2002:a5d:6684:: with SMTP id l4mr19570945wru.381.1615653494995; Sat, 13 Mar 2021 08:38:14 -0800 (PST) Received: from localhost.localdomain ([197.61.164.30]) by smtp.googlemail.com with ESMTPSA id n6sm13173441wrt.1.2021.03.13.08.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 08:38:14 -0800 (PST) From: Mahmoud Mandour To: qemu-devel@nongnu.org Subject: [PATCH 9/9] tools/virtiofsd: Replacing malloc-like calls with GLib's variants Date: Sat, 13 Mar 2021 18:36:53 +0200 Message-Id: <20210313163653.37089-10-ma.mandourr@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210313163653.37089-1-ma.mandourr@gmail.com> References: <20210313163653.37089-1-ma.mandourr@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=ma.mandourr@gmail.com; helo=mail-wr1-x42b.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+incoming=patchwork.ozlabs.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);