From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 3EABD38582A3 for ; Thu, 22 Dec 2022 22:55:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3EABD38582A3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BMLx8hY007086 for ; Thu, 22 Dec 2022 22:55:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=uHCft9Jq7X7eO1tj+saJNn/Zr5UCSzIcUOQ7xBtsfRU=; b=ZII3LF9lM+8uycxQGXjxpyPFjLVTESynhulFKh9WVAd/dea6oKRgDaAzj2enl9/3VpgB 6pCBY6GPvJMKvf69OOnpM70eAHnhh7TiDwf97LafRg8gXV8hr/OHQvMO8fMJH7rrCnH9 7hIwc7Nll5UmELqMA7NM15sWNhfROIPxztYJvudI/2Mi/7c5FZ795mBIGNN1yXbCW6vJ KqJ1a2bwItbAG7PQpKyE2lUaYYir/8e5tS74B1tfE5ckrVd7M3CJDLUmN9jJfBM7cAo1 BgU6MljJHxJpbwl7lO0sy8Uehp1WWQAKvIbB5WaErLESTaobh12YIi8pcDYyfykybRuw zg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mh6tpvsay-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Dec 2022 22:55:07 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BMK278k035217 for ; Thu, 22 Dec 2022 22:55:05 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mh47evqca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 22 Dec 2022 22:55:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ccl/84B0wP98QCMw/9xLLyiP4HxV85CQVI7BTu9rlGg1yfu40G+IcHarGwC9e2b0qqLl2ual9xluQxQou3Vy7RUboojjRQs25RtOGXgEPNIs9hmxNP4uDacWuTeBeGxabsZ/yjOkPFWhjN9IXNrsUz6Ev+SkuEjJUsJ24WuBmX+pLaFma8poFWpFxYkziVWS/Gkjgp9lNk8sbNQVQD8pds7TJqNwZ/vmaSCdZfO4xpaQBkypX7oDSGMn4lw590+npAxrav0xv6a81pZVHr5vHkvS+4pzA0PcX7d5gmEX9Of8xAq/6lg7ODfyhVcY5TVIVf2OGkwDxjsVx9PAw5bByA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uHCft9Jq7X7eO1tj+saJNn/Zr5UCSzIcUOQ7xBtsfRU=; b=loA0RTFQ3V68mkeDahj+205H151PgWIago2A+w39LNBe1eyjyudd/8f8Tns6FaqS3WtxsjwTH3R4DY/vrR0bkOPbjO2i9ltERsWcQ9gWjYYD4e2DLPS+KVL1ZH7tUosKBCB+8afo29/xRejZ/50baNXfUSkI2G++ziZj39HqnhkOPPQzMGQDAZtiLcHxmrwt/91HaG5w5IiNwH5wVu2u8RSfQ/L9+Ctrzy4NI9+pnDg5cnjsaokf/+HnRphdTH+JhcVNjdrrv1tVKHZg3SE+v9VXX1LfI61li0gW1Pm43Er3PhEBCAbc3Pk3Zukn7ZZMHYAdytVM0MS5AfuKirYvAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uHCft9Jq7X7eO1tj+saJNn/Zr5UCSzIcUOQ7xBtsfRU=; b=lrNZ4oNYu261/qSe0w4GvM7uBHoQBIUV2lz+Fes0YAeVnLqC2brcyydcGo6YAiYy83piv4NiygU4igiGpGyswyo1lHHGvdEH/9xuvMrkKPh+n9KcF6XROovF8dM+tfC6RZwKHv7TQ/9K5lPkvgq0AdGBF82XaqQUQpvlmFZ8/bM= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by IA1PR10MB7513.namprd10.prod.outlook.com (2603:10b6:208:451::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Thu, 22 Dec 2022 22:55:03 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc%5]) with mapi id 15.20.5924.016; Thu, 22 Dec 2022 22:55:03 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: Indu Bhagat Subject: [PATCH 1/2] libsframe: fix a memory leak in sframe_decode Date: Thu, 22 Dec 2022 14:54:56 -0800 Message-Id: <20221222225457.1095930-2-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221222225457.1095930-1-indu.bhagat@oracle.com> References: <20221222225457.1095930-1-indu.bhagat@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4P221CA0029.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::34) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|IA1PR10MB7513:EE_ X-MS-Office365-Filtering-Correlation-Id: 616f0080-ae81-40b2-c031-08dae46f8fb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D6h6x1KGmWE4DyFEzi3O+gfsLtES54H7uobcsiixUgYr8XWTL+D82sCgz3PIjB8FyI55nVgNFXbYrY+ZRPJPeFmOmgp2LKVqzf2nSzvDesAX7GXNvChq0kRsY60RvLauS0lPPEkYDBc1v6C2zGeINCTVbQgXDapPqwbs/yx7lOMUm0buZ3tN2o+/KPL8l9mQl+9206qpRrT9gi4pb/YBuRArXDhWuRS4uD9dktrKkJuYzf6r5gGteOTsTTAynhyf/Kv1qgZm1nya+45tuAzKYsJzbklK2MpCL0oWY+Aq9+JLQ27MHnq5Um/N1b94Zjo2TxXVWebV6rXV+OEyJQ/MlP1grf7ey76vAqgv9Jc6fiklS1gdcvrfDby8DFxxfQO5XvFVcgkSg9ZYej3BN8mFrFVGujDHrWqhepw4MJO/z75eiD1GA2hxDoSJyO0qqhbOuJ4m18A5NzRrhfo8rHY9d9ny8WTwilqEZhCW/EmunkIZrR0WMI+tuc0FxUqtHJ/04343jlCib4bAtQE7EWGYDCnFYdEql1YOyHVNroYpOJ8IHLXVZuusvrpsRxHPYQopEFzGirJQ1tgPl0rdatopcBdWh8YTHvGOHAbjrTgd6A7eB/kszLpN3lb+JUBEX2OX X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2158.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(39860400002)(136003)(366004)(396003)(346002)(376002)(451199015)(44832011)(38100700002)(478600001)(6916009)(6486002)(4326008)(8936002)(36756003)(5660300002)(316002)(66476007)(66556008)(66946007)(86362001)(8676002)(83380400001)(26005)(2906002)(2616005)(41300700001)(6666004)(6506007)(6512007)(186003)(1076003)(107886003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?/F/6PnmNuwVhi7oOlcVIKtRAy4wKoZMD1n8umlLL/UzvV+XVsNhRFXWyBBEf?= =?us-ascii?Q?nBPx8al9uW/RQZaaTsYM38K8v5se/fahL2QDAQNx9EqX3IDd5ON5XI/tHGdb?= =?us-ascii?Q?hscF8DFCQH1gD1QtHyISrybCGGmr0vZjBqMxrGNRFP/t1JoiWeSDSZZW4maV?= =?us-ascii?Q?M5u0+G+w3zJwSAibzsM2e4YkAz1PfzaN410p3qaSdUPhY6XR1Oqna9GcFNk0?= =?us-ascii?Q?I7CYtZADZCyHKM237I/1yw1ZF2PQWqlOjDxFm971cyMMgTgwtRTJSZ/Io2+K?= =?us-ascii?Q?risxBsiu3ntLhnetWoUYRAKZkgZV72IF/q4WVbOKwAzeTEXntfdDb8uj5yH7?= =?us-ascii?Q?NWpZXDJT5n0CyunXpGSTT8BBFbrT5Y6NeCJQ6919V2lxy9kPXK8fvcCxFB1b?= =?us-ascii?Q?1WFspp4CIx73bMR9/94AztdD1PMsvnmM0dJzEVUPPQ5EV73RWluAlR8qT2Po?= =?us-ascii?Q?lTklpQx+FwuJcrakWTckLYccB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?iMr2CNh/gM0mSVgaQXDOS7iTIcrw2tC4is3vmZolvhn3KHNrkEFiUJcn4yzd?= =?us-ascii?Q?GxnW7Fd0ZEDqFiRbnOXq0DkXD3HqK9Gh/6jlxaKHmZlcshaJmvEfV1eXk+fZ?= =?us-ascii?Q?zXUoL3eGnQ6MEnfIrVkx13J7anJ1Wahfqf7jBET0ES8RSfEmKO9QEohk6exV?= =?us-ascii?Q?1+MCZOdzOJJ7pRHCJMZPKmiTTsDEKW46jj8hVDRG?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 616f0080-ae81-40b2-c031-08dae46f8fb6 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Dec 2022 22:55:03.1061 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1JNAid/fUFETgYnM760ru9kSoHpdej823CTYnLMu0fOyXFtvmCvC/Vx+y7KalLyQ8/X5Bqg/dyKz2RpLk+Iapw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB7513 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-22_10,2022-12-22_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2212220193 X-Proofpoint-ORIG-GUID: 6WUjAdJGHBmCnXsKcaerwRZoPB7KnTSM X-Proofpoint-GUID: 6WUjAdJGHBmCnXsKcaerwRZoPB7KnTSM X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: sframe_decode () needs to malloc a temporary buffer of the same size as the input buffer (containing the SFrame section bytes) when endian flipping is needed. The decoder keeps the endian flipped contents in this buffer for its usage. This code is necessary when the target endianneess is not the same as host endianness. The malloc'd buffer needs to be kept track of, so that it can freed up in sframe_decoder_free () later. ChangeLog: * libsframe/sframe-impl.h (struct sframe_decoder_ctx): Add new member to keep track of the internally malloc'd buffer. * libsframe/sframe.c (sframe_decoder_free): Free it up. (sframe_decode): Update the reference to the buffer. --- libsframe/sframe-impl.h | 15 +++++++++++---- libsframe/sframe.c | 9 +++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libsframe/sframe-impl.h b/libsframe/sframe-impl.h index 0e61c977886..340d3b35042 100644 --- a/libsframe/sframe-impl.h +++ b/libsframe/sframe-impl.h @@ -32,10 +32,17 @@ extern "C" struct sframe_decoder_ctx { - sframe_header sfd_header; /* SFrame header. */ - uint32_t *sfd_funcdesc; /* SFrame function desc entries table. */ - void *sfd_fres; /* SFrame FRE table. */ - int sfd_fre_nbytes; /* Number of bytes needed for SFrame FREs. */ + /* SFrame header. */ + sframe_header sfd_header; + /* SFrame function desc entries table. */ + uint32_t *sfd_funcdesc; + /* SFrame FRE table. */ + void *sfd_fres; + /* Number of bytes needed for SFrame FREs. */ + int sfd_fre_nbytes; + /* Reference to the internally malloc'd buffer, if any, for endian flipping + the original input buffer before decoding. */ + void *sfd_buf; }; struct sframe_encoder_ctx diff --git a/libsframe/sframe.c b/libsframe/sframe.c index b8fde2f04f8..e41c95b9944 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -548,6 +548,11 @@ sframe_decoder_free (sframe_decoder_ctx **decoder) free (dctx->sfd_fres); dctx->sfd_fres = NULL; } + if (dctx->sfd_buf != NULL) + { + free (dctx->sfd_buf); + dctx->sfd_buf = NULL; + } free (*decoder); *decoder = NULL; @@ -824,6 +829,10 @@ sframe_decode (const char *sf_buf, size_t sf_size, int *errp) return sframe_ret_set_errno (errp, SFRAME_ERR_BUF_INVAL); } frame_buf = tempbuf; + /* This buffer is malloc'd when endian flipping the contents of the input + buffer are needed. Keep a reference to it so it can be free'd up + later in sframe_decoder_free (). */ + dctx->sfd_buf = tempbuf; } else frame_buf = (char *)sf_buf; -- 2.37.2