diff options
| author | Chong Yidong | 2008-12-08 14:44:30 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-12-08 14:44:30 +0000 |
| commit | d31eee5eccaab4f86222be76ddb383bf9db2188c (patch) | |
| tree | c0ff5422c5c537444f9c0d27c562a599bd2debcc | |
| parent | d93264c67823a87a01f723f0618bbdf173d7415f (diff) | |
| download | emacs-d31eee5eccaab4f86222be76ddb383bf9db2188c.tar.gz emacs-d31eee5eccaab4f86222be76ddb383bf9db2188c.zip | |
(encode_terminal_code): Free any previous memory blocks
before calling xmalloc for encode_terminal_src or
encode_terminal_dst.
(maybe_fatal): Buffer argument deleted. Don't free buffer here.
All callers changed.
(init_tty): Store termcap data and string buffers in new struct
tty members termcap_term_buffer and termcap_strings_buffer.
(delete_tty): Free them.
(syms_of_term): Initialize encode_terminal_src and
encode_terminal_dst.
| -rw-r--r-- | src/term.c | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/term.c b/src/term.c index 5b71ce4f284..32bc4f6eea8 100644 --- a/src/term.c +++ b/src/term.c | |||
| @@ -581,10 +581,10 @@ encode_terminal_code (src, src_len, coding) | |||
| 581 | required = MAX_MULTIBYTE_LENGTH * src_len; | 581 | required = MAX_MULTIBYTE_LENGTH * src_len; |
| 582 | if (encode_terminal_src_size < required) | 582 | if (encode_terminal_src_size < required) |
| 583 | { | 583 | { |
| 584 | if (encode_terminal_src_size == 0) | 584 | if (encode_terminal_src) |
| 585 | encode_terminal_src = xmalloc (required); | ||
| 586 | else | ||
| 587 | encode_terminal_src = xrealloc (encode_terminal_src, required); | 585 | encode_terminal_src = xrealloc (encode_terminal_src, required); |
| 586 | else | ||
| 587 | encode_terminal_src = xmalloc (required); | ||
| 588 | encode_terminal_src_size = required; | 588 | encode_terminal_src_size = required; |
| 589 | } | 589 | } |
| 590 | 590 | ||
| @@ -740,7 +740,11 @@ encode_terminal_code (src, src_len, coding) | |||
| 740 | if (encode_terminal_dst_size == 0) | 740 | if (encode_terminal_dst_size == 0) |
| 741 | { | 741 | { |
| 742 | encode_terminal_dst_size = encode_terminal_src_size; | 742 | encode_terminal_dst_size = encode_terminal_src_size; |
| 743 | encode_terminal_dst = xmalloc (encode_terminal_dst_size); | 743 | if (encode_terminal_dst) |
| 744 | encode_terminal_dst = xrealloc (encode_terminal_dst, | ||
| 745 | encode_terminal_dst_size); | ||
| 746 | else | ||
| 747 | encode_terminal_dst = xmalloc (encode_terminal_dst_size); | ||
| 744 | } | 748 | } |
| 745 | coding->destination = encode_terminal_dst; | 749 | coding->destination = encode_terminal_dst; |
| 746 | coding->dst_bytes = encode_terminal_dst_size; | 750 | coding->dst_bytes = encode_terminal_dst_size; |
| @@ -3326,7 +3330,6 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 3326 | { | 3330 | { |
| 3327 | char *area = NULL; | 3331 | char *area = NULL; |
| 3328 | char **address = &area; | 3332 | char **address = &area; |
| 3329 | char *buffer = NULL; | ||
| 3330 | int buffer_size = 4096; | 3333 | int buffer_size = 4096; |
| 3331 | register char *p = NULL; | 3334 | register char *p = NULL; |
| 3332 | int status; | 3335 | int status; |
| @@ -3335,7 +3338,7 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 3335 | int ctty = 0; /* 1 if asked to open controlling tty. */ | 3338 | int ctty = 0; /* 1 if asked to open controlling tty. */ |
| 3336 | 3339 | ||
| 3337 | if (!terminal_type) | 3340 | if (!terminal_type) |
| 3338 | maybe_fatal (must_succeed, 0, 0, | 3341 | maybe_fatal (must_succeed, 0, |
| 3339 | "Unknown terminal type", | 3342 | "Unknown terminal type", |
| 3340 | "Unknown terminal type"); | 3343 | "Unknown terminal type"); |
| 3341 | 3344 | ||
| @@ -3356,7 +3359,7 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 3356 | terminal = create_terminal (); | 3359 | terminal = create_terminal (); |
| 3357 | #ifdef MSDOS | 3360 | #ifdef MSDOS |
| 3358 | if (been_here > 0) | 3361 | if (been_here > 0) |
| 3359 | maybe_fatal (1, 0, 0, "Attempt to create another terminal %s", "", | 3362 | maybe_fatal (1, 0, "Attempt to create another terminal %s", "", |
| 3360 | name, ""); | 3363 | name, ""); |
| 3361 | been_here = 1; | 3364 | been_here = 1; |
| 3362 | tty = &the_only_display_info; | 3365 | tty = &the_only_display_info; |
| @@ -3397,14 +3400,14 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 3397 | #endif /* O_IGNORE_CTTY */ | 3400 | #endif /* O_IGNORE_CTTY */ |
| 3398 | 3401 | ||
| 3399 | if (fd < 0) | 3402 | if (fd < 0) |
| 3400 | maybe_fatal (must_succeed, buffer, terminal, | 3403 | maybe_fatal (must_succeed, terminal, |
| 3401 | "Could not open file: %s", | 3404 | "Could not open file: %s", |
| 3402 | "Could not open file: %s", | 3405 | "Could not open file: %s", |
| 3403 | name); | 3406 | name); |
| 3404 | if (!isatty (fd)) | 3407 | if (!isatty (fd)) |
| 3405 | { | 3408 | { |
| 3406 | close (fd); | 3409 | close (fd); |
| 3407 | maybe_fatal (must_succeed, buffer, terminal, | 3410 | maybe_fatal (must_succeed, terminal, |
| 3408 | "Not a tty device: %s", | 3411 | "Not a tty device: %s", |
| 3409 | "Not a tty device: %s", | 3412 | "Not a tty device: %s", |
| 3410 | name); | 3413 | name); |
| @@ -3504,22 +3507,22 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 3504 | 3507 | ||
| 3505 | Wcm_clear (tty); | 3508 | Wcm_clear (tty); |
| 3506 | 3509 | ||
| 3507 | buffer = (char *) xmalloc (buffer_size); | 3510 | tty->termcap_term_buffer = (char *) xmalloc (buffer_size); |
| 3508 | 3511 | ||
| 3509 | /* On some systems, tgetent tries to access the controlling | 3512 | /* On some systems, tgetent tries to access the controlling |
| 3510 | terminal. */ | 3513 | terminal. */ |
| 3511 | sigblock (sigmask (SIGTTOU)); | 3514 | sigblock (sigmask (SIGTTOU)); |
| 3512 | status = tgetent (buffer, terminal_type); | 3515 | status = tgetent (tty->termcap_term_buffer, terminal_type); |
| 3513 | sigunblock (sigmask (SIGTTOU)); | 3516 | sigunblock (sigmask (SIGTTOU)); |
| 3514 | 3517 | ||
| 3515 | if (status < 0) | 3518 | if (status < 0) |
| 3516 | { | 3519 | { |
| 3517 | #ifdef TERMINFO | 3520 | #ifdef TERMINFO |
| 3518 | maybe_fatal (must_succeed, buffer, terminal, | 3521 | maybe_fatal (must_succeed, terminal, |
| 3519 | "Cannot open terminfo database file", | 3522 | "Cannot open terminfo database file", |
| 3520 | "Cannot open terminfo database file"); | 3523 | "Cannot open terminfo database file"); |
| 3521 | #else | 3524 | #else |
| 3522 | maybe_fatal (must_succeed, buffer, terminal, | 3525 | maybe_fatal (must_succeed, terminal, |
| 3523 | "Cannot open termcap database file", | 3526 | "Cannot open termcap database file", |
| 3524 | "Cannot open termcap database file"); | 3527 | "Cannot open termcap database file"); |
| 3525 | #endif | 3528 | #endif |
| @@ -3527,7 +3530,7 @@ init_tty (char *name, char *terminal_type, int must_succeed) | |||
| 3527 | if (status == 0) | 3530 | if (status == 0) |
| 3528 | { | 3531 | { |
| 3529 | #ifdef TERMINFO | 3532 | #ifdef TERMINFO |
| 3530 | maybe_fatal (must_succeed, buffer, terminal, | 3533 | maybe_fatal (must_succeed, terminal, |
| 3531 | "Terminal type %s is not defined", | 3534 | "Terminal type %s is not defined", |
| 3532 | "Terminal type %s is not defined.\n\ | 3535 | "Terminal type %s is not defined.\n\ |
| 3533 | If that is not the actual type of terminal you have,\n\ | 3536 | If that is not the actual type of terminal you have,\n\ |
| @@ -3536,7 +3539,7 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ | |||
| 3536 | to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", | 3539 | to do `unset TERMINFO' (C-shell: `unsetenv TERMINFO') as well.", |
| 3537 | terminal_type); | 3540 | terminal_type); |
| 3538 | #else | 3541 | #else |
| 3539 | maybe_fatal (must_succeed, buffer, terminal, | 3542 | maybe_fatal (must_succeed, terminal, |
| 3540 | "Terminal type %s is not defined", | 3543 | "Terminal type %s is not defined", |
| 3541 | "Terminal type %s is not defined.\n\ | 3544 | "Terminal type %s is not defined.\n\ |
| 3542 | If that is not the actual type of terminal you have,\n\ | 3545 | If that is not the actual type of terminal you have,\n\ |
| @@ -3548,12 +3551,11 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", | |||
| 3548 | } | 3551 | } |
| 3549 | 3552 | ||
| 3550 | #ifndef TERMINFO | 3553 | #ifndef TERMINFO |
| 3551 | if (strlen (buffer) >= buffer_size) | 3554 | if (strlen (tty->termcap_term_buffer) >= buffer_size) |
| 3552 | abort (); | 3555 | abort (); |
| 3553 | buffer_size = strlen (buffer); | 3556 | buffer_size = strlen (tty->termcap_term_buffer); |
| 3554 | #endif | 3557 | #endif |
| 3555 | area = (char *) xmalloc (buffer_size); | 3558 | tty->termcap_strings_buffer = area = (char *) xmalloc (buffer_size); |
| 3556 | |||
| 3557 | tty->TS_ins_line = tgetstr ("al", address); | 3559 | tty->TS_ins_line = tgetstr ("al", address); |
| 3558 | tty->TS_ins_multi_lines = tgetstr ("AL", address); | 3560 | tty->TS_ins_multi_lines = tgetstr ("AL", address); |
| 3559 | tty->TS_bell = tgetstr ("bl", address); | 3561 | tty->TS_bell = tgetstr ("bl", address); |
| @@ -3690,7 +3692,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", | |||
| 3690 | FrameRows (tty) = tgetnum ("li"); | 3692 | FrameRows (tty) = tgetnum ("li"); |
| 3691 | 3693 | ||
| 3692 | if (FrameRows (tty) < 3 || FrameCols (tty) < 3) | 3694 | if (FrameRows (tty) < 3 || FrameCols (tty) < 3) |
| 3693 | maybe_fatal (must_succeed, NULL, terminal, | 3695 | maybe_fatal (must_succeed, terminal, |
| 3694 | "Screen size %dx%d is too small" | 3696 | "Screen size %dx%d is too small" |
| 3695 | "Screen size %dx%d is too small", | 3697 | "Screen size %dx%d is too small", |
| 3696 | FrameCols (tty), FrameRows (tty)); | 3698 | FrameCols (tty), FrameRows (tty)); |
| @@ -3814,7 +3816,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", | |||
| 3814 | 3816 | ||
| 3815 | if (Wcm_init (tty) == -1) /* can't do cursor motion */ | 3817 | if (Wcm_init (tty) == -1) /* can't do cursor motion */ |
| 3816 | { | 3818 | { |
| 3817 | maybe_fatal (must_succeed, NULL, terminal, | 3819 | maybe_fatal (must_succeed, terminal, |
| 3818 | "Terminal type \"%s\" is not powerful enough to run Emacs", | 3820 | "Terminal type \"%s\" is not powerful enough to run Emacs", |
| 3819 | # ifdef TERMINFO | 3821 | # ifdef TERMINFO |
| 3820 | "Terminal type \"%s\" is not powerful enough to run Emacs.\n\ | 3822 | "Terminal type \"%s\" is not powerful enough to run Emacs.\n\ |
| @@ -3835,7 +3837,7 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", | |||
| 3835 | } | 3837 | } |
| 3836 | 3838 | ||
| 3837 | if (FrameRows (tty) <= 0 || FrameCols (tty) <= 0) | 3839 | if (FrameRows (tty) <= 0 || FrameCols (tty) <= 0) |
| 3838 | maybe_fatal (must_succeed, NULL, terminal, | 3840 | maybe_fatal (must_succeed, terminal, |
| 3839 | "Could not determine the frame size", | 3841 | "Could not determine the frame size", |
| 3840 | "Could not determine the frame size"); | 3842 | "Could not determine the frame size"); |
| 3841 | 3843 | ||
| @@ -3868,9 +3870,6 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", | |||
| 3868 | 3870 | ||
| 3869 | init_baud_rate (fileno (tty->input)); | 3871 | init_baud_rate (fileno (tty->input)); |
| 3870 | 3872 | ||
| 3871 | /* Don't do this. I think termcap may still need the buffer. */ | ||
| 3872 | /* xfree (buffer); */ | ||
| 3873 | |||
| 3874 | #endif /* not DOS_NT */ | 3873 | #endif /* not DOS_NT */ |
| 3875 | 3874 | ||
| 3876 | /* Init system terminal modes (RAW or CBREAK, etc.). */ | 3875 | /* Init system terminal modes (RAW or CBREAK, etc.). */ |
| @@ -3880,18 +3879,15 @@ to do `unset TERMCAP' (C-shell: `unsetenv TERMCAP') as well.", | |||
| 3880 | } | 3879 | } |
| 3881 | 3880 | ||
| 3882 | /* Auxiliary error-handling function for init_tty. | 3881 | /* Auxiliary error-handling function for init_tty. |
| 3883 | Free BUFFER and delete TERMINAL, then call error or fatal | 3882 | Delete TERMINAL, then call error or fatal with str1 or str2, |
| 3884 | with str1 or str2, respectively, according to MUST_SUCCEED. */ | 3883 | respectively, according to MUST_SUCCEED. */ |
| 3885 | 3884 | ||
| 3886 | static void | 3885 | static void |
| 3887 | maybe_fatal (must_succeed, buffer, terminal, str1, str2, arg1, arg2) | 3886 | maybe_fatal (must_succeed, terminal, str1, str2, arg1, arg2) |
| 3888 | int must_succeed; | 3887 | int must_succeed; |
| 3889 | char *buffer; | ||
| 3890 | struct terminal *terminal; | 3888 | struct terminal *terminal; |
| 3891 | char *str1, *str2, *arg1, *arg2; | 3889 | char *str1, *str2, *arg1, *arg2; |
| 3892 | { | 3890 | { |
| 3893 | xfree (buffer); | ||
| 3894 | |||
| 3895 | if (terminal) | 3891 | if (terminal) |
| 3896 | delete_tty (terminal); | 3892 | delete_tty (terminal); |
| 3897 | 3893 | ||
| @@ -3989,6 +3985,10 @@ delete_tty (struct terminal *terminal) | |||
| 3989 | 3985 | ||
| 3990 | xfree (tty->old_tty); | 3986 | xfree (tty->old_tty); |
| 3991 | xfree (tty->Wcm); | 3987 | xfree (tty->Wcm); |
| 3988 | if (tty->termcap_strings_buffer) | ||
| 3989 | xfree (tty->termcap_strings_buffer); | ||
| 3990 | if (tty->termcap_term_buffer) | ||
| 3991 | xfree (tty->termcap_term_buffer); | ||
| 3992 | 3992 | ||
| 3993 | bzero (tty, sizeof (struct tty_display_info)); | 3993 | bzero (tty, sizeof (struct tty_display_info)); |
| 3994 | xfree (tty); | 3994 | xfree (tty); |
| @@ -4061,6 +4061,9 @@ bigger, or it may make it blink, or it may do nothing at all. */); | |||
| 4061 | default_set_foreground = NULL; | 4061 | default_set_foreground = NULL; |
| 4062 | default_set_background = NULL; | 4062 | default_set_background = NULL; |
| 4063 | #endif /* !DOS_NT */ | 4063 | #endif /* !DOS_NT */ |
| 4064 | |||
| 4065 | encode_terminal_src = NULL; | ||
| 4066 | encode_terminal_dst = NULL; | ||
| 4064 | } | 4067 | } |
| 4065 | 4068 | ||
| 4066 | 4069 | ||