From patchwork Sat Nov 27 11:40:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31759 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp3531393iob; Sat, 27 Nov 2021 03:40:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzv2dDXtHeE+9ZD92SEMQPdkPpJI+fkeyr6gasY1mIQ14W3XK1J5Yaf4oA79fmuKu/eTq37 X-Received: by 2002:a05:6402:60c:: with SMTP id n12mr56496660edv.17.1638013258759; Sat, 27 Nov 2021 03:40:58 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e19si15331555ejs.586.2021.11.27.03.40.58; Sat, 27 Nov 2021 03:40:58 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=d0Tj9SFf; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B761568AE97; Sat, 27 Nov 2021 13:40:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074036.outbound.protection.outlook.com [40.92.74.36]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F99968009F for ; Sat, 27 Nov 2021 13:40:49 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Un++lT3o1qx216EMC44fUzj88y/fqa2Yr0MDZ1W0LJet+2GOO5c+gwm/Jzf6fQ013CZYc1aWhNkHXsGVUxQGAy1HvfvhhFy0Yyc4PDNvXy4uhq1rlNYbcg8hQqBcJzgnrglBVjPSZhtn4jvBYLdZIkWG7XX8+GjZ4Z0p75oZi6s4+yTIdTjmw7SFYvdFLsc7IlNdX64tH8Z5LuAXkBrx1Bz29x8SCOY3Gihp0SBNNQxkXaUdS29r7zwvTxfQs/qUwmZzSloj2JuOdiwcgYxveEb2qWm/oVRui4izkGL3FFoQNcYmJBpisXVRdG6IPlQmKAjbuS9MSS9HtlORf19LIA== 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=RfN4+MhorUbQ/mZc1czxRXvEq03wi1Zb0aqA6zEt4/U=; b=mY5ZRvAkQBKatnnrWQa2czXMWHdfqMInX+2k1Nv2/5q4MTiyNgQcqKvEEkXWXjX2ONR6rsT5uwuyLNKp+460qSYjMPP3iMvaIajPlVkaercTjtSwrj7mkj8O1Z5YOy7zDK+k4hcoJ4olBa0isnTuuRpavFURmwL8tUN8cjB0IkAZRCR8BWgKI0trwMmibc3Is1O4SR+8ZvCI3rU5Fza+S/oeGpe5/n6Ylc1yf/sO1QQ/s/me72c+sQ5rppNkqcYrc269bGq+vpmwPSjJC+xiXwZ1KJq4ykXbVv7lk8M5YjMG7kyMLCt8b8KXTEKBRgJLZAheO7pPDF1J2Fm9NM4Ung== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RfN4+MhorUbQ/mZc1czxRXvEq03wi1Zb0aqA6zEt4/U=; b=d0Tj9SFfs7cv6Ltk7bxXpA7Wq2ecnNOsxLMHImWY8hJGZC1FFxrKzo+GaIg1r+bB2/EtvW3rvwIvAMsWTtMwHlmuQuIW/GSb/0bz6JaZR3uCWoMSxIrBZCkuICgOJb2RQj8TPjOmms3C0rpD5FheJlNmZGkG+cbp8RzIFHs9vUB3NVeBezDM7NxR00XTBj01BchGsqVXB1Tx615J4pD9rCjMws4U6+YAsWdjFwm/H8VZuzxiM3GB8e3v2yKjFDyusgm36A9c64g4ibkx2E7+Qdx7a2NRDcs8ceg3NNgjgCgs3oYUDsWRAGDpTTYyiic1QMzt948i2Nxi1leuLjDhbg== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR0302MB3320.eurprd03.prod.outlook.com (2603:10a6:209:22::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Sat, 27 Nov 2021 11:40:47 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%9]) with mapi id 15.20.4734.023; Sat, 27 Nov 2021 11:40:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 27 Nov 2021 12:40:25 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 X-TMN: [fNJ9yuey2szRmT+G56wVlAajyKnOKdcL] X-ClientProxiedBy: AS8PR04CA0053.eurprd04.prod.outlook.com (2603:10a6:20b:312::28) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211127114025.104376-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.248.74) by AS8PR04CA0053.eurprd04.prod.outlook.com (2603:10a6:20b:312::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.19 via Frontend Transport; Sat, 27 Nov 2021 11:40:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebd9bb47-843f-4dbf-0cff-08d9b19ac142 X-MS-Exchange-SLBlob-MailProps: GjjEsbJCp87y9vb6M/JCv3n+eMmMHWc3sSr+7Dr3OVGiNnOtXPBLNdtxH37w8aHVpZmAgwNdcDTi4M2PNlJt5YUzm5N8r1u0I6q5T9AcJUbeA+fHi4rRnb5MEO/2L7XZFsvAELp0FHy2LH0fQzzWC3Jfx/+hC2pUVDPKfVo1a69mUW9xLa8ct7sHaeJr8qoHB0E8gNdwHCm//zznFY+XfF1rffX3z+n3M6vcbdfUZrRkGlCzYONozAzRYLzTZCnPyNR7tqWHPjg8gtgCBt0aiCnE7myxuIkZPJlg8T79ovcRnMh6R9d5f37maV+kavpun7MhozYg8a40Yt87NB08pSWW9vIH6T1fnEGdL3lbvD+O7Akhy5901cFivjWWvyvjuGUXG8ftgsVT+BFfNKZNRnFXqXDwkEtoO4oVy6Kp9t6bnzn9UJUmZRNVkssWTHxV0CPUZK0Z4a8x2Kw61WzU2W1hNUsysFf1JEGwBFulCZkk0bAXtQzkc/9k2f/Wy5RIWV6deTf3kM7m3p3iubYFYjaiVDV5Zcq3TxIJFFTtWwTGjMq+JHi9gkLEscGLGpVsONDMwxfmcf/qVWi0662USpXS8Umhfqqe1/Qh831r/oc9SWI1iVrEcvDt2sZtDiRTIKMeTfw4tijTrtzpnq4D6B+p1PPvNx6NWcBgtxM5txIcmCvn+5XgFyGe+t0e2rYRQDMK05yRD9XlxIUDDquGLJlYCeYuIYttrvUUHLj2FFqgAm6v2pIIRF5tmDhwG5r9U0jADD9FMNRCy6nUl4lXmKnCPYb3Z8IJ1sME2ei6g/zGvLqCl7vb1/JLUtDHEtUFOdL+DBMuR2u6Qkx3Kk98/icc+6mzKXTclG8pvE3jea5jrzdKHslWTQ== X-MS-TrafficTypeDiagnostic: AM6PR0302MB3320: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KVM+vDxfn7M3arvo9cdOX0JDeuv8YAu67Am7w69G2i+a7mNRv1h6uJ35DqEEc/w/6QA78WDW3m2DCrNwTgwYuiERD9PUBOfsI5YpWr9F+R2BTrAXtPWP2dURvFhWJOdZnQlc33omV7xUtRX/MO4LIm4/xM3IYbfQTkaJBYZHRdHljnCtosaJCPyG44FzhHyYeE7re5u3vlhYcfrz0npp997urlMWXMf7i8OimHaHqx8k2rklld02FgQs4b+ARf7TjeF7VxQJPX8WPV4mZ6bEPukCVXVoQzRv7/mLS2UPNEvCEDZ4apklk+D3Xtv/8lkaVfkCjgAxRxK5pRNInsYz4i4AE2wrttN4GjyZlLyWIKC7ne9rtq/PLGjTBYRr8LL+SbumI89B+hlr51GVNdJw/F1hoEdPYFGGzpWdoS3MYh57/GQ9YaeKU8m/Vf39kpBbg1qRl/8Dcv6S4QRqvJewpt51jkpPTFikZgeFYC8Vjf7gVuduFTBRdV4DOlPpG7mehKZkpzkUjSWWSZBjWAA6f47hstOgJhh5dhWk6Odg9UoZzHlZ46lQT2gBaFNj/029cJxO9dzT3YXzmLTqxFY7zg== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hwOckGxsbSnnk2t7Sfyz2xp7CtUPFLEEZnbj5Q9c/7lf9cO9+tIhLhEgkgVCPWT8c2TQUjawtIdGCYHSZ29Q4gzcdjuKyUSPhItxJgEPmvRVMBXsk3cGt79xYpJo1+mYxOi670DTf6E4ol+ga1DT+PeuLml99VEnBawXfrwUSj3X5C0TJU4rT2PuNvY6IYyikFQ/nbYJQzS3s2LRb4VHZgJSZAdOCUd8xh29KDAsBJhZeu1CgRD4/Z1rCKCx8if4Qq9QVQP4lbcMVejecr06aDR9ax7pUnV6pZ1HA/Y5VLfmlL78i715o6+zDRGk53gFmgJ8/AVlzZjIafZSp/cC0Q7fxTR3LtsylGqBC02E/mz/ma/NMnkurZQpro+WzUHa9c8IkaAuyrCJvoFb9vzzvCdC1ZIi0Yxfz/naXZT4D6kplXYVvcFceNe0RKxbdCZ7+7elkzRgPRPKCqLzB5WD5qcx9RE4qBEZKTptlGG6fccFd7ox0JBMNld8T8e6h+BNgWDX5lx3uVN2lsDfIwLJy3wkDpvYWOocujJ5lDbvxMKS9ohc/U1wvQQ08dsvLKAQC95wnROQHG1oEiNglzMySmjdj/Y3ckrfgd0BeWOsVALWuulLJaHj6ZsFjlGPXKOYlZPnsUplvq0wc9hVozw8oSyt5Wn/5XTTFrRIORaP66FRcyrfAdDAQf0OfIRvsEHggXLUlE6tsA1soHYueJ4URzeC++cS5dp69Zos68RcHgwhuyzEhfprE2yA3PIOEX9v6xOuRUFV8rAdVrzsr3InFgOG7IT84fTViPs5p7kL6s/2axKV0kxfBW/wJ0nQtbbjyuKzXTav7lmH+/YBDe86dAJ7D0U+yAqdES7o1oSXYRzq27Aw7DPLtr6YdGtuCiPUu0PtyX8/c4T52zdktCdu9M83epHOfbfO00i/aEve2wiRJh78fIVqPr3vn4fA3tjlCtNkKCShURhH/79xvFHf2Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebd9bb47-843f-4dbf-0cff-08d9b19ac142 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Nov 2021 11:40:47.7048 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0302MB3320 Subject: [FFmpeg-devel] [PATCH] all: Use av_memdup() where appropriate X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RILWkytNVE23 Signed-off-by: Andreas Rheinhardt --- libavcodec/decode.c | 4 +--- libavcodec/dvbsubdec.c | 8 ++------ libavcodec/g723_1enc.c | 3 +-- libavformat/hdsenc.c | 6 ++---- libavformat/mpegts.c | 3 +-- libavformat/oggparsevorbis.c | 3 +-- libavformat/rtsp.c | 3 +-- libavutil/bprint.c | 6 ++---- 8 files changed, 11 insertions(+), 25 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index c44724d150..52bf5dcd33 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1104,12 +1104,10 @@ int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) avctx->sw_pix_fmt = fmt[n - 1]; } - choices = av_malloc_array(n + 1, sizeof(*choices)); + choices = av_memdup(fmt, (n + 1) * sizeof(*choices)); if (!choices) return AV_PIX_FMT_NONE; - memcpy(choices, fmt, (n + 1) * sizeof(*choices)); - for (;;) { // Remove the previous hwaccel, if there was one. hwaccel_uninit(avctx); diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c index d192f3251d..81ccaf4c57 100644 --- a/libavcodec/dvbsubdec.c +++ b/libavcodec/dvbsubdec.c @@ -823,14 +823,12 @@ static int save_subtitle_set(AVCodecContext *avctx, AVSubtitle *sub, int *got_ou } memcpy(rect->data[1], clut_table, (1 << region->depth) * sizeof(*clut_table)); - rect->data[0] = av_malloc(region->buf_size); + rect->data[0] = av_memdup(region->pbuf, region->buf_size); if (!rect->data[0]) { ret = AVERROR(ENOMEM); goto fail; } - memcpy(rect->data[0], region->pbuf, region->buf_size); - if ((clut == &default_clut && ctx->compute_clut < 0) || ctx->compute_clut == 1) { if (!region->has_computed_clut) { compute_default_clut(ctx, region->computed_clut, rect, rect->w, rect->h); @@ -1074,12 +1072,10 @@ static int dvbsub_parse_clut_segment(AVCodecContext *avctx, clut = get_clut(ctx, clut_id); if (!clut) { - clut = av_malloc(sizeof(*clut)); + clut = av_memdup(&default_clut, sizeof(*clut)); if (!clut) return AVERROR(ENOMEM); - memcpy(clut, &default_clut, sizeof(*clut)); - clut->id = clut_id; clut->version = -1; diff --git a/libavcodec/g723_1enc.c b/libavcodec/g723_1enc.c index 2b3cccee09..2a8149b4cd 100644 --- a/libavcodec/g723_1enc.c +++ b/libavcodec/g723_1enc.c @@ -1116,10 +1116,9 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, HFParam hf[4]; /* duplicate input */ - start = in = av_malloc(frame->nb_samples * sizeof(int16_t)); + start = in = av_memdup(frame->data[0], frame->nb_samples * sizeof(int16_t)); if (!in) return AVERROR(ENOMEM); - memcpy(in, frame->data[0], frame->nb_samples * sizeof(int16_t)); highpass_filter(in, &p->hpf_fir_mem, &p->hpf_iir_mem); diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c index e5353bac65..64d9f1413d 100644 --- a/libavformat/hdsenc.c +++ b/libavformat/hdsenc.c @@ -93,19 +93,17 @@ static int parse_header(OutputStream *os, const uint8_t *buf, int buf_size) if (os->nb_extra_packets >= FF_ARRAY_ELEMS(os->extra_packets)) return AVERROR_INVALIDDATA; os->extra_packet_sizes[os->nb_extra_packets] = size; - os->extra_packets[os->nb_extra_packets] = av_malloc(size); + os->extra_packets[os->nb_extra_packets] = av_memdup(buf, size); if (!os->extra_packets[os->nb_extra_packets]) return AVERROR(ENOMEM); - memcpy(os->extra_packets[os->nb_extra_packets], buf, size); os->nb_extra_packets++; } else if (type == 0x12) { if (os->metadata) return AVERROR_INVALIDDATA; os->metadata_size = size - 11 - 4; - os->metadata = av_malloc(os->metadata_size); + os->metadata = av_memdup(buf + 11, os->metadata_size); if (!os->metadata) return AVERROR(ENOMEM); - memcpy(os->metadata, buf + 11, os->metadata_size); } buf += size; buf_size -= size; diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index 36ab7ab3af..2479cb6f7d 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -938,10 +938,9 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, // audio track - add a second stream for this AVStream *sub_st; // priv_data cannot be shared between streams - PESContext *sub_pes = av_malloc(sizeof(*sub_pes)); + PESContext *sub_pes = av_memdup(pes, sizeof(*sub_pes)); if (!sub_pes) return AVERROR(ENOMEM); - memcpy(sub_pes, pes, sizeof(*sub_pes)); sub_st = avformat_new_stream(pes->stream, NULL); if (!sub_st) { diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c index 77e8d301b2..e1ef510892 100644 --- a/libavformat/oggparsevorbis.c +++ b/libavformat/oggparsevorbis.c @@ -320,10 +320,9 @@ static int vorbis_header(AVFormatContext *s, int idx) return priv->vp ? 0 : AVERROR_INVALIDDATA; priv->len[pkt_type >> 1] = os->psize; - priv->packet[pkt_type >> 1] = av_mallocz(os->psize); + priv->packet[pkt_type >> 1] = av_memdup(os->buf + os->pstart, os->psize); if (!priv->packet[pkt_type >> 1]) return AVERROR(ENOMEM); - memcpy(priv->packet[pkt_type >> 1], os->buf + os->pstart, os->psize); if (os->buf[os->pstart] == 1) { const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */ unsigned blocksize, bs0, bs1; diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index a1aa969cad..abd448246d 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -383,10 +383,9 @@ static void copy_default_source_addrs(struct RTSPSource **addrs, int count, int i; for (i = 0; i < count; i++) { rtsp_src = addrs[i]; - rtsp_src2 = av_malloc(sizeof(*rtsp_src2)); + rtsp_src2 = av_memdup(rtsp_src, sizeof(*rtsp_src)); if (!rtsp_src2) continue; - memcpy(rtsp_src2, rtsp_src, sizeof(*rtsp_src)); dynarray_add(dest, dest_count, rtsp_src2); } } diff --git a/libavutil/bprint.c b/libavutil/bprint.c index a6849d7178..ea51d9b09c 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -244,10 +244,8 @@ int av_bprint_finalize(AVBPrint *buf, char **ret_str) str = buf->str; buf->str = NULL; } else { - str = av_malloc(real_size); - if (str) - memcpy(str, buf->str, real_size); - else + str = av_memdup(buf->str, real_size); + if (!str) ret = AVERROR(ENOMEM); } *ret_str = str;