- merge forgotten uninit from work branch - add set_str() function to free before overwriting - fix some other leaks
Unified · Split
| @@ -153,7 +153,6 @@ typedef struct MermaidContext { · 152 unmodified lines | |||
| 153 | } section_data[SECTION_MAX_NB_LEVELS]; | 153 | } section_data[SECTION_MAX_NB_LEVELS]; |
| 154 | 154 | ||
| 155 | unsigned nb_link_captions[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section, | 155 | unsigned nb_link_captions[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section, |
| 156 | AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section, | ||
| 157 | AVBPrint link_buf; ///< print buffer for writing diagram links | 156 | AVBPrint link_buf; ///< print buffer for writing diagram links |
| 158 | AVDictionary *link_dict; | 157 | AVDictionary *link_dict; |
| 159 | } MermaidContext; | 158 | } MermaidContext; |
| @@ -216,6 +215,32 @@ static av_cold int mermaid_init_html(AVTextFormatContext *tfc) · 56 unmodified lines | |||
| 216 | return 0; | 215 | return 0; |
| 217 | } | 216 | } |
| 218 | 217 | ||
| 218 | static av_cold int mermaid_uninit(AVTextFormatContext *tfc) | ||
| 219 | { | ||
| 220 | MermaidContext *mmc = tfc->priv; | ||
| 221 | |||
| 222 | av_bprint_finalize(&mmc->link_buf, NULL); | ||
| 223 | av_dict_free(&mmc->link_dict); | ||
| 224 | |||
| 225 | for (unsigned i = 0; i < SECTION_MAX_NB_LEVELS; i++) { | ||
| 226 | av_freep(&mmc->section_data[i].dest_id); | ||
| 227 | av_freep(&mmc->section_data[i].section_id); | ||
| 228 | av_freep(&mmc->section_data[i].src_id); | ||
| 229 | av_freep(&mmc->section_data[i].section_type); | ||
| 230 | } | ||
| 231 | |||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | |||
| 235 | static void set_str(const char **dst, const char *src) | ||
| 236 | { | ||
| 237 | if (*dst) | ||
| 238 | av_freep(dst); | ||
| 239 | |||
| 240 | if (src) | ||
| 241 | *dst = av_strdup(src); | ||
| 242 | } | ||
| 243 | |||
| 219 | #define MM_INDENT() writer_printf(tfc, "%*c", mmc->indent_level * 2, ' ') | 244 | #define MM_INDENT() writer_printf(tfc, "%*c", mmc->indent_level * 2, ' ') |
| 220 | 245 | ||
| 221 | static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *data) | 246 | 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 · 44 unmodified lines | |||
| 266 | break; | 291 | break; |
| 267 | } | 292 | } |
| 268 | 293 | ||
| 294 | av_bprint_finalize(&css_buf, NULL); | ||
| 295 | av_freep(&directive); | ||
| 269 | return; | 296 | return; |
| 270 | } | 297 | } |
| 271 | 298 | ||
| @@ -310,7 +337,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d · 38 unmodified lines | |||
| 310 | } | 337 | } |
| 311 | 338 | ||
| 312 | mmc->section_data[tfc->level].subgraph_start_incomplete = 1; | 339 | mmc->section_data[tfc->level].subgraph_start_incomplete = 1; |
| 313 | mmc->section_data[tfc->level].section_id = av_strdup(sec_ctx->context_id); | 340 | set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); |
| 314 | } | 341 | } |
| 315 | 342 | ||
| 316 | if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SHAPE) { | 343 | if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_SHAPE) { |
| @@ -322,7 +349,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d · 5 unmodified lines | |||
| 322 | 349 | ||
| 323 | if (sec_ctx->context_id) { | 350 | if (sec_ctx->context_id) { |
| 324 | 351 | ||
| 325 | mmc->section_data[tfc->level].section_id = av_strdup(sec_ctx->context_id); | 352 | set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); |
| 326 | 353 | ||
| 327 | switch (mmc->diagram_config->diagram_type) { | 354 | switch (mmc->diagram_config->diagram_type) { |
| 328 | case AV_DIAGRAMTYPE_GRAPH: | 355 | case AV_DIAGRAMTYPE_GRAPH: |
| @@ -352,7 +379,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d · 23 unmodified lines | |||
| 352 | av_log(tfc, AV_LOG_ERROR, "Unable to write shape start. Missing id field. Section: %s", section->name); | 379 | av_log(tfc, AV_LOG_ERROR, "Unable to write shape start. Missing id field. Section: %s", section->name); |
| 353 | } | 380 | } |
| 354 | 381 | ||
| 355 | mmc->section_data[tfc->level].section_id = av_strdup(sec_ctx->context_id); | 382 | set_str(&mmc->section_data[tfc->level].section_id, sec_ctx->context_id); |
| 356 | } | 383 | } |
| 357 | 384 | ||
| 358 | 385 | ||
| @@ -371,7 +398,7 @@ static void mermaid_print_section_header(AVTextFormatContext *tfc, const void *d · 12 unmodified lines | |||
| 371 | mmc->nb_link_captions[tfc->level] = 0; | 398 | mmc->nb_link_captions[tfc->level] = 0; |
| 372 | 399 | ||
| 373 | if (sec_ctx && sec_ctx->context_type) | 400 | if (sec_ctx && sec_ctx->context_type) |
| 374 | mmc->section_data[tfc->level].section_type = av_strdup(sec_ctx->context_type); | 401 | set_str(&mmc->section_data[tfc->level].section_type, sec_ctx->context_type); |
| 375 | 402 | ||
| 376 | ////if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { | 403 | ////if (section->flags & AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE) { |
| 377 | //// AVBPrint buf; | 404 | //// AVBPrint buf; |
| @@ -533,17 +560,17 @@ static void mermaid_print_value(AVTextFormatContext *tfc, const char *key, · 155 unmodified lines | |||
| 533 | int exit = 0; | 560 | int exit = 0; |
| 534 | 561 | ||
| 535 | if (section->id_key && !strcmp(section->id_key, key)) { | 562 | if (section->id_key && !strcmp(section->id_key, key)) { |
| 536 | mmc->section_data[tfc->level].section_id = av_strdup(str); | 563 | set_str(&mmc->section_data[tfc->level].section_id, str); |
| 537 | exit = 1; | 564 | exit = 1; |
| 538 | } | 565 | } |
| 539 | 566 | ||
| 540 | if (section->dest_id_key && !strcmp(section->dest_id_key, key)) { | 567 | if (section->dest_id_key && !strcmp(section->dest_id_key, key)) { |
| 541 | mmc->section_data[tfc->level].dest_id = av_strdup(str); | 568 | set_str(&mmc->section_data[tfc->level].dest_id, str); |
| 542 | exit = 1; | 569 | exit = 1; |
| 543 | } | 570 | } |
| 544 | 571 | ||
| 545 | if (section->src_id_key && !strcmp(section->src_id_key, key)) { | 572 | if (section->src_id_key && !strcmp(section->src_id_key, key)) { |
| 546 | mmc->section_data[tfc->level].src_id = av_strdup(str); | 573 | set_str(&mmc->section_data[tfc->level].src_id, str); |
| 547 | exit = 1; | 574 | exit = 1; |
| 548 | } | 575 | } |
| 549 | 576 | ||
| @@ -636,6 +663,7 @@ const AVTextFormatter avtextformatter_mermaid = { · 86 unmodified lines | |||
| 636 | .name = "mermaid", | 663 | .name = "mermaid", |
| 637 | .priv_size = sizeof(MermaidContext), | 664 | .priv_size = sizeof(MermaidContext), |
| 638 | .init = mermaid_init, | 665 | .init = mermaid_init, |
| 666 | .uninit = mermaid_uninit, | ||
| 639 | .print_section_header = mermaid_print_section_header, | 667 | .print_section_header = mermaid_print_section_header, |
| 640 | .print_section_footer = mermaid_print_section_footer, | 668 | .print_section_footer = mermaid_print_section_footer, |
| 641 | .print_integer = mermaid_print_int, | 669 | .print_integer = mermaid_print_int, |
| @@ -649,6 +677,7 @@ const AVTextFormatter avtextformatter_mermaidhtml = { · 7 unmodified lines | |||
| 649 | .name = "mermaidhtml", | 677 | .name = "mermaidhtml", |
| 650 | .priv_size = sizeof(MermaidContext), | 678 | .priv_size = sizeof(MermaidContext), |
| 651 | .init = mermaid_init_html, | 679 | .init = mermaid_init_html, |
| 680 | .uninit = mermaid_uninit, | ||
| 652 | .print_section_header = mermaid_print_section_header, | 681 | .print_section_header = mermaid_print_section_header, |
| 653 | .print_section_footer = mermaid_print_section_footer, | 682 | .print_section_footer = mermaid_print_section_footer, |
| 654 | .print_integer = mermaid_print_int, | 683 | .print_integer = mermaid_print_int, |