(expand_string, run_test, run_mailcap): Fix memory
allocation bugs. Place all temporary strings on the obstack.
Showing
1 changed file
with
12 additions
and
12 deletions
... | @@ -319,7 +319,6 @@ expand_string (struct mime_context *ct, char **pstr) | ... | @@ -319,7 +319,6 @@ expand_string (struct mime_context *ct, char **pstr) |
319 | } | 319 | } |
320 | } | 320 | } |
321 | obstack_1grow (&expand_stack, 0); | 321 | obstack_1grow (&expand_stack, 0); |
322 | free (*pstr); | ||
323 | *pstr = obstack_finish (&expand_stack); | 322 | *pstr = obstack_finish (&expand_stack); |
324 | return rc; | 323 | return rc; |
325 | } | 324 | } |
... | @@ -494,12 +493,14 @@ run_test (mu_mailcap_entry_t entry, struct mime_context *ctx) | ... | @@ -494,12 +493,14 @@ run_test (mu_mailcap_entry_t entry, struct mime_context *ctx) |
494 | { | 493 | { |
495 | int argc; | 494 | int argc; |
496 | char **argv; | 495 | char **argv; |
497 | char *str = xmalloc (size + 1); | 496 | char *str; |
497 | |||
498 | obstack_blank (&expand_stack, size + 1); | ||
499 | str = obstack_finish (&expand_stack); | ||
498 | mu_mailcap_entry_get_test (entry, str, size + 1, NULL); | 500 | mu_mailcap_entry_get_test (entry, str, size + 1, NULL); |
499 | 501 | ||
500 | expand_string (ctx, &str); | 502 | expand_string (ctx, &str); |
501 | mu_argcv_get (str, "", NULL, &argc, &argv); | 503 | mu_argcv_get (str, "", NULL, &argc, &argv); |
502 | free (str); | ||
503 | 504 | ||
504 | if (mu_spawnvp (argv[0], argv, &status)) | 505 | if (mu_spawnvp (argv[0], argv, &status)) |
505 | status = 1; | 506 | status = 1; |
... | @@ -528,9 +529,11 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) | ... | @@ -528,9 +529,11 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) |
528 | 529 | ||
529 | if (interactive_p (ctx)) | 530 | if (interactive_p (ctx)) |
530 | { | 531 | { |
531 | mu_mailcap_entry_get_viewcommand (entry, NULL, 0, &size); | 532 | if (mu_mailcap_entry_get_viewcommand (entry, NULL, 0, &size)) |
533 | return 1; | ||
532 | size++; | 534 | size++; |
533 | view_command = xmalloc (size); | 535 | obstack_blank (&expand_stack, size); |
536 | view_command = obstack_finish (&expand_stack); | ||
534 | mu_mailcap_entry_get_viewcommand (entry, view_command, size, NULL); | 537 | mu_mailcap_entry_get_viewcommand (entry, view_command, size, NULL); |
535 | } | 538 | } |
536 | else | 539 | else |
... | @@ -538,7 +541,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) | ... | @@ -538,7 +541,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) |
538 | if (mu_mailcap_entry_get_value (entry, "print", NULL, 0, &size)) | 541 | if (mu_mailcap_entry_get_value (entry, "print", NULL, 0, &size)) |
539 | return 1; | 542 | return 1; |
540 | size++; | 543 | size++; |
541 | view_command = xmalloc (size); | 544 | obstack_blank (&expand_stack, size); |
545 | view_command = obstack_finish (&expand_stack); | ||
542 | mu_mailcap_entry_get_value (entry, "print", view_command, size, NULL); | 546 | mu_mailcap_entry_get_value (entry, "print", view_command, size, NULL); |
543 | } | 547 | } |
544 | 548 | ||
... | @@ -551,11 +555,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) | ... | @@ -551,11 +555,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) |
551 | DEBUG (ctx, 0, (_("Executing %s...\n"), view_command)); | 555 | DEBUG (ctx, 0, (_("Executing %s...\n"), view_command)); |
552 | 556 | ||
553 | if (!confirm_action (ctx, view_command)) | 557 | if (!confirm_action (ctx, view_command)) |
554 | { | 558 | return 1; |
555 | free (view_command); | 559 | |
556 | return 1; | ||
557 | } | ||
558 | |||
559 | flag = 0; | 560 | flag = 0; |
560 | if (interactive_p (ctx) | 561 | if (interactive_p (ctx) |
561 | && mu_mailcap_entry_copiousoutput (entry, &flag) == 0 && flag) | 562 | && mu_mailcap_entry_copiousoutput (entry, &flag) == 0 && flag) |
... | @@ -579,7 +580,6 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) | ... | @@ -579,7 +580,6 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx) |
579 | if (ctx->debug_level) | 580 | if (ctx->debug_level) |
580 | print_exit_status (status); | 581 | print_exit_status (status); |
581 | } | 582 | } |
582 | free (view_command); | ||
583 | return 0; | 583 | return 0; |
584 | } | 584 | } |
585 | 585 | ... | ... |
-
Please register or sign in to post a comment