From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 237EF47307 for ; Tue, 20 May 2025 02:06:27 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 121CE68D198; Tue, 20 May 2025 05:05:42 +0300 (EEST) Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id DB6CC68C087 for ; Tue, 20 May 2025 05:05:39 +0300 (EEST) Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-306b6ae4fb2so4062723a91.3 for ; Mon, 19 May 2025 19:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747706738; x=1748311538; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=diQ0iQhXGSmRXpfjGd5cSDn+jF+EiPlqzloUOKW88EI=; b=AFdblp2KIkHCfro4+t3SNSi5mL/QdMa7NMK72LsZzkDSwvpWnWbzLKFpIxBWxCUkM+ S9hlfs7wQ6E+dRzOzf4a9/NKHwloMOyI3pfAfNm1JMf2tQXyvnr9GAsQPwqfoHw9W7HD 22Ox0DhDIyPZ/DOnT1OQ9LpJhC2truOhuNrbkELRxz3qoc4xd3UurG5SH608qlCMypxe NcEpN9Oy9/5Emuu1h3shTl+qcbGRMJ3ondYEvlWWi9GfNTQFKoh6o5aksL4FbR4SxN78 dpiIzFVL2krwZ5UzU3Gx1WpcmPIsj8RYrj76kqOlhOTydB0Aygp3QVc1ixsX1TFSaM66 cKTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747706738; x=1748311538; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=diQ0iQhXGSmRXpfjGd5cSDn+jF+EiPlqzloUOKW88EI=; b=oHk4PlGsYyG+VZzXzcMZVnRIEhv80su46dqe8j3/2CjvqM5o9ZOHv1t/5QaMPqfL4p fGQn9IOMxYjl4bgF5ZLcR1EeZNZuOd9mwTPXGMkXjpYYWX3LBUWx82kg20zAn2QqpCdb Th4bKQ+5z7lFyWWw9ibv6QbkFBvNHAkV1uPdJKlmGMsL5oB7HKUVKPxkeOJ25o0VHUGf wz4/7yZHzs0aV+DIMociSbhK2KY0NtMTRqkwtxoM+e9FjkkZexYpSg9lVdzIJQzsewYv v6yuWl19Qk73RR2Lc72GjstE12ausw9B3ClPRnNZyGxzQBjeGxpyWwvRf32pk2H/zW9Q WJtA== X-Gm-Message-State: AOJu0YzljFknsDt6pHV6uF3kvOwtJUSkpE4n+iOv6+UBnlHatjJM79Tb j0TYT6j6NbxNsuU0ZPdkM51YmK/bgpFwrqK7NFRqcCiuPMVxMIa9DhXO4WheyQ== X-Gm-Gg: ASbGncu4LqoaLdZJI7N0myM8aX98SqLOmBh0Nm6igqBvhxUFQQQGlP1V41L4KlNXqo0 Xwf5q+F9/4/5vq0nM0wF1jMqoJnLIkP0KWLtVIAFxDEjHf0ajfZBtugbr49F4jSR4n0+uEbOpcA nc/KWWYElfeJEQWTVS9Ey3qxP6AENpsBvVFp5IsG+uDQHyTtvFByWr+3G8XVBuamoT7NF+1/db1 3hAGSKcmxmBGz200RYcr1vEdCodc9iwRfOeH5Jn7yPG9b4/18l1Pra6upooLpUTWibeYYHh6XxU bzisMT3IzKCoPzG1Z5LFtm6mr0Z2ax6GGxC6a6zZuIx4k+u71uZTeo4vsqrxANgtoFGhd9mjU5r I10H/ X-Google-Smtp-Source: AGHT+IE95fOEXHbn5w6/u+5i3ZLAIdbZAJYykCSWGS/0EHzsacbXsDgpR3AuznH+WlmdOndsNFTN+g== X-Received: by 2002:a17:90b:51cd:b0:30e:7ad7:ec8c with SMTP id 98e67ed59e1d1-30e7d55be50mr23048830a91.20.1747706737959; Mon, 19 May 2025 19:05:37 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-30f365e5b51sm417023a91.32.2025.05.19.19.05.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 May 2025 19:05:37 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <061618f324e3d3a5de0cdeb99fb39d65c030502a.1747706704.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Tue, 20 May 2025 02:05:04 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 5/5] fftools/tf_mermaid: Add missing uninit and fix leaks 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: softworkz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: softworkz - merge forgotten uninit from work branch - add set_str() function to free before overwriting - fix some other leaks Signed-off-by: softworkz --- fftools/textformat/tf_mermaid.c | 45 +++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/fftools/textformat/tf_mermaid.c b/fftools/textformat/tf_mermaid.c index 6147cf6eea..d3b9131ada 100644 --- a/fftools/textformat/tf_mermaid.c +++ b/fftools/textformat/tf_mermaid.c @@ -153,7 +153,6 @@ typedef struct MermaidContext { } section_data[SECTION_MAX_NB_LEVELS]; unsigned nb_link_captions[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section, - AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section, AVBPrint link_buf; ///< print buffer for writing diagram links AVDictionary *link_dict; } MermaidContext; @@ -216,6 +215,32 @@ static av_cold int mermaid_init_html(AVTextFormatContext *tfc) return 0; } +static av_cold int mermaid_uninit(AVTextFormatContext *tfc) +{ + MermaidContext *mmc = tfc->priv; + + av_bprint_finalize(&mmc->link_buf, NULL); + av_dict_free(&mmc->link_dict); + + for (unsigned i = 0; i < SECTION_MAX_NB_LEVELS; i++) { + av_freep(&mmc->section_data[i].dest_id); + av_freep(&mmc->section_data[i].section_id); + av_freep(&mmc->section_data[i].src_id); + av_freep(&mmc->section_data[i].section_type); + } + + return 0; +} + +static void set_str(const char **dst, const char *src) +{ + if (*dst) + av_freep(dst); + + if (src) + *dst = av_strdup(src); +} + #define MM_INDENT() writer_printf(tfc, "%*c", mmc->indent_level * 2, ' ') static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *data) @@ -266,6 +291,8 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d break; } + av_bprint_finalize(&css_buf, NULL); + av_freep(&directive); return; } @@ -310,7 +337,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d } mmc->section_data[tfc->level].subgraph_start_incomplete = 1; - mmc->section_data[tfc->level].section_id = av_strdup(sec_ctx->context_id); + set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); } if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SHAPE) { @@ -322,7 +349,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d if (sec_ctx->context_id) { - mmc->section_data[tfc->level].section_id = av_strdup(sec_ctx->context_id); + set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); switch (mmc->diagram_config->diagram_type) { case AV_DIAGRAMTYPE_GRAPH: @@ -352,7 +379,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d av_log(tfc, AV_LOG_ERROR, "Unable to write shape start. Missing id field. Section: %s", section->name); } - mmc->section_data[tfc->level].section_id = av_strdup(sec_ctx->context_id); + set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); } @@ -371,7 +398,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d mmc->nb_link_captions[tfc->level] = 0; if (sec_ctx && sec_ctx->context_type) - mmc->section_data[tfc->level].section_type = av_strdup(sec_ctx->context_type); + set_str(&mmc->section_data[tfc->level].section_type, sec_ctx->context_type); ////if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { //// AVBPrint buf; @@ -533,17 +560,17 @@ static void mermaid_print_value(AVTextFormatContext *tfc, const char *key, int exit = 0; if (section->id_key && !strcmp(section->id_key, key)) { - mmc->section_data[tfc->level].section_id = av_strdup(str); + set_str(&mmc->section_data[tfc->level].section_id, str); exit = 1; } if (section->dest_id_key && !strcmp(section->dest_id_key, key)) { - mmc->section_data[tfc->level].dest_id = av_strdup(str); + set_str(&mmc->section_data[tfc->level].dest_id, str); exit = 1; } if (section->src_id_key && !strcmp(section->src_id_key, key)) { - mmc->section_data[tfc->level].src_id = av_strdup(str); + set_str(&mmc->section_data[tfc->level].src_id, str); exit = 1; } @@ -636,6 +663,7 @@ const AVTextFormatter avtextformatter_mermaid = { .name = "mermaid", .priv_size = sizeof(MermaidContext), .init = mermaid_init, + .uninit = mermaid_uninit, .print_section_header = mermaid_print_section_header, .print_section_footer = mermaid_print_section_footer, .print_integer = mermaid_print_int, @@ -649,6 +677,7 @@ const AVTextFormatter avtextformatter_mermaidhtml = { .name = "mermaidhtml", .priv_size = sizeof(MermaidContext), .init = mermaid_init_html, + .uninit = mermaid_uninit, .print_section_header = mermaid_print_section_header, .print_section_footer = mermaid_print_section_footer, .print_integer = mermaid_print_int, -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".