From: softworkz <ffmpegagent@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: softworkz <softworkz@hotmail.com> Subject: [FFmpeg-devel] [PATCH 5/5] fftools/tf_mermaid: Add missing uninit and fix leaks Date: Tue, 20 May 2025 02:05:04 +0000 Message-ID: <061618f324e3d3a5de0cdeb99fb39d65c030502a.1747706704.git.ffmpegagent@gmail.com> (raw) In-Reply-To: <pull.84.ffstaging.FFmpeg.1747706704.ffmpegagent@gmail.com> From: softworkz <softworkz@hotmail.com> - merge forgotten uninit from work branch - add set_str() function to free before overwriting - fix some other leaks Signed-off-by: softworkz <softworkz@hotmail.com> --- 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".
prev parent reply other threads:[~2025-05-20 2:06 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-05-20 2:04 [FFmpeg-devel] [PATCH 0/5] Graphprint and Mermaid Fixes ffmpegagent 2025-05-20 2:05 ` [FFmpeg-devel] [PATCH 1/5] fftools/makefile: Remove resources from ffprobe softworkz 2025-05-20 2:05 ` [FFmpeg-devel] [PATCH 2/5] fftools/resources: Use .SECONDARY in Makefile comment softworkz 2025-05-20 2:05 ` [FFmpeg-devel] [PATCH 3/5] fftools/ffmpeg: Free print_graph option variables softworkz 2025-05-20 2:05 ` [FFmpeg-devel] [PATCH 4/5] fftools/graphprint: Fix memory leaks softworkz 2025-05-20 2:05 ` softworkz [this message]
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=061618f324e3d3a5de0cdeb99fb39d65c030502a.1747706704.git.ffmpegagent@gmail.com \ --to=ffmpegagent@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ --cc=softworkz@hotmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git