From nobody Mon Feb 9 10:47:48 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1615653771; cv=none; d=zohomail.com; s=zohoarc; b=S/8DLk+Kq2UX9ILNsFShiQJgs8drV5qX84XzzHRV9Xhd2lUxslbTcNnTMGe9TVGJINvh74aNayAPHvvRb3eJFSamzvB6vAqv1oZJk+VE0HfvRmwCJSR68hLYYcIosPxvS1wNsimf3hhDDolgskC+FVzz+kmMdcRG6Fh1X2qakds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615653771; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sg5nGgHTBeRiuxmxPZ+wz0jzsIryQrfg1B3YEn8ftJE=; b=lKqFBSaKZQnyz42BarI4QHPEgH4E9vb4d7pBdQyi2/g+/nSO7+bfhojspRwTaeMvROdvgYCPseCkMFj/rph1uwXQSmT2oBegFcFNOfELYWOUqOxQooftI2A2vQmuh76dFbgUJo+pAGyCuLXpqYWYX1tbxQaF9ew6EYOZvIYqfe0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615653771311117.90813153505542; Sat, 13 Mar 2021 08:42:51 -0800 (PST) Received: from localhost ([::1]:35546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lL7Lm-0006sV-9h for importer@patchew.org; Sat, 13 Mar 2021 11:42:50 -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) 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) 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) Content-Type: text/plain; charset="utf-8" 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; =20 /* allocate dynamic tables */ - if((TL_TABLE =3D malloc(TL_MAX * 2 * sizeof(int32_t))) =3D=3D NULL) + if((TL_TABLE =3D g_try_new(int32_t, TL_MAX * 2)) =3D=3D NULL) return 0; - if((SIN_TABLE =3D malloc(SIN_ENT * 4 *sizeof(int32_t *))) =3D=3D NULL) + if((SIN_TABLE =3D g_try_new(int32_t *, SIN_ENT * 4)) =3D=3D NULL) { - free(TL_TABLE); + g_free(TL_TABLE); return 0; } - if((AMS_TABLE =3D malloc(AMS_ENT * 2 * sizeof(int32_t))) =3D=3D NULL) + if((AMS_TABLE =3D g_try_new(int32_t, AMS_ENT * 2)) =3D=3D NULL) { - free(TL_TABLE); - free(SIN_TABLE); + g_free(TL_TABLE); + g_free(SIN_TABLE); return 0; } - if((VIB_TABLE =3D malloc(VIB_ENT *2 * sizeof(int32_t))) =3D=3D NULL) + if((VIB_TABLE =3D g_try_new(int32_t, VIB_ENT * 2)) =3D=3D 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 =3D g_try_new(int32_t, 2 * EG_ENT + 1)) =3D=3D NULL) + { + g_free(TL_TABLE); + g_free(SIN_TABLE); + g_free(AMS_TABLE); + g_free(VIB_TABLE); return 0; } - ENV_CURVE =3D g_new(int32_t, 2 * EG_ENT + 1); /* make total level table */ for (t =3D 0;t < EG_ENT-1 ;t++){ rate =3D ((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); } =20 /* CSM Key Control */ @@ -1082,7 +1089,7 @@ FM_OPL *OPLCreate(int clock, int rate) state_size =3D sizeof(FM_OPL); state_size +=3D sizeof(OPL_CH)*max_ch; /* allocate memory block */ - ptr =3D malloc(state_size); + ptr =3D g_try_malloc(state_size); if(ptr=3D=3DNULL) 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); } =20 /* ---------- Option handlers ---------- */ --=20 2.25.1