comparison src/window.c @ 4287:dc3efb6d5a08 v7.3.893

updated for version 7.3.893 Problem: Crash when using b:, w: or t: after closing the buffer, window or tabpage. Solution: Allocate the dictionary instead of having it part of the buffer/window/tabpage struct. (Yukihiro Nakadaira)
author Bram Moolenaar <bram@vim.org>
date Mon, 15 Apr 2013 12:27:36 +0200
parents 48b54c590dc8
children b01e3cff9253
comparison
equal deleted inserted replaced
4286:afcc61d24129 4287:dc3efb6d5a08
3455 */ 3455 */
3456 static tabpage_T * 3456 static tabpage_T *
3457 alloc_tabpage() 3457 alloc_tabpage()
3458 { 3458 {
3459 tabpage_T *tp; 3459 tabpage_T *tp;
3460 # ifdef FEAT_GUI
3461 int i;
3462 # endif
3463
3460 3464
3461 tp = (tabpage_T *)alloc_clear((unsigned)sizeof(tabpage_T)); 3465 tp = (tabpage_T *)alloc_clear((unsigned)sizeof(tabpage_T));
3462 if (tp != NULL) 3466 if (tp == NULL)
3463 { 3467 return NULL;
3468
3469 # ifdef FEAT_EVAL
3470 /* init t: variables */
3471 tp->tp_vars = dict_alloc();
3472 if (tp->tp_vars == NULL)
3473 {
3474 vim_free(tp);
3475 return NULL;
3476 }
3477 init_var_dict(tp->tp_vars, &tp->tp_winvar, VAR_SCOPE);
3478 # endif
3479
3464 # ifdef FEAT_GUI 3480 # ifdef FEAT_GUI
3465 int i; 3481 for (i = 0; i < 3; i++)
3466 3482 tp->tp_prev_which_scrollbars[i] = -1;
3467 for (i = 0; i < 3; i++)
3468 tp->tp_prev_which_scrollbars[i] = -1;
3469 # endif 3483 # endif
3470 # ifdef FEAT_DIFF 3484 # ifdef FEAT_DIFF
3471 tp->tp_diff_invalid = TRUE; 3485 tp->tp_diff_invalid = TRUE;
3472 # endif 3486 # endif
3473 #ifdef FEAT_EVAL 3487 tp->tp_ch_used = p_ch;
3474 /* init t: variables */ 3488
3475 init_var_dict(&tp->tp_vars, &tp->tp_winvar, VAR_SCOPE);
3476 #endif
3477 tp->tp_ch_used = p_ch;
3478 }
3479 return tp; 3489 return tp;
3480 } 3490 }
3481 3491
3482 void 3492 void
3483 free_tabpage(tp) 3493 free_tabpage(tp)
3489 diff_clear(tp); 3499 diff_clear(tp);
3490 # endif 3500 # endif
3491 for (idx = 0; idx < SNAP_COUNT; ++idx) 3501 for (idx = 0; idx < SNAP_COUNT; ++idx)
3492 clear_snapshot(tp, idx); 3502 clear_snapshot(tp, idx);
3493 #ifdef FEAT_EVAL 3503 #ifdef FEAT_EVAL
3494 vars_clear(&tp->tp_vars.dv_hashtab); /* free all t: variables */ 3504 vars_clear(&tp->tp_vars->dv_hashtab); /* free all t: variables */
3505 hash_init(&tp->tp_vars->dv_hashtab);
3506 unref_var_dict(tp->tp_vars);
3495 #endif 3507 #endif
3496 vim_free(tp); 3508 vim_free(tp);
3497 } 3509 }
3498 3510
3499 /* 3511 /*
4361 4373
4362 /* 4374 /*
4363 * allocate window structure and linesizes arrays 4375 * allocate window structure and linesizes arrays
4364 */ 4376 */
4365 new_wp = (win_T *)alloc_clear((unsigned)sizeof(win_T)); 4377 new_wp = (win_T *)alloc_clear((unsigned)sizeof(win_T));
4366 if (new_wp != NULL && win_alloc_lines(new_wp) == FAIL) 4378 if (new_wp == NULL)
4379 return NULL;
4380
4381 if (win_alloc_lines(new_wp) == FAIL)
4367 { 4382 {
4368 vim_free(new_wp); 4383 vim_free(new_wp);
4369 new_wp = NULL; 4384 return NULL;
4370 } 4385 }
4371 4386
4372 if (new_wp != NULL) 4387 #ifdef FEAT_EVAL
4373 { 4388 /* init w: variables */
4389 new_wp->w_vars = dict_alloc();
4390 if (new_wp->w_vars == NULL)
4391 {
4392 win_free_lsize(new_wp);
4393 vim_free(new_wp);
4394 return NULL;
4395 }
4396 init_var_dict(new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE);
4397 #endif
4398
4374 #ifdef FEAT_AUTOCMD 4399 #ifdef FEAT_AUTOCMD
4375 /* Don't execute autocommands while the window is not properly 4400 /* Don't execute autocommands while the window is not properly
4376 * initialized yet. gui_create_scrollbar() may trigger a FocusGained 4401 * initialized yet. gui_create_scrollbar() may trigger a FocusGained
4377 * event. */ 4402 * event. */
4378 block_autocmds(); 4403 block_autocmds();
4379 #endif 4404 #endif
4380 /* 4405 /*
4381 * link the window in the window list 4406 * link the window in the window list
4382 */ 4407 */
4383 #ifdef FEAT_WINDOWS 4408 #ifdef FEAT_WINDOWS
4384 if (!hidden) 4409 if (!hidden)
4385 win_append(after, new_wp); 4410 win_append(after, new_wp);
4386 #endif 4411 #endif
4387 #ifdef FEAT_VERTSPLIT 4412 #ifdef FEAT_VERTSPLIT
4388 new_wp->w_wincol = 0; 4413 new_wp->w_wincol = 0;
4389 new_wp->w_width = Columns; 4414 new_wp->w_width = Columns;
4390 #endif 4415 #endif
4391 4416
4392 /* position the display and the cursor at the top of the file. */ 4417 /* position the display and the cursor at the top of the file. */
4393 new_wp->w_topline = 1; 4418 new_wp->w_topline = 1;
4394 #ifdef FEAT_DIFF 4419 #ifdef FEAT_DIFF
4395 new_wp->w_topfill = 0; 4420 new_wp->w_topfill = 0;
4396 #endif 4421 #endif
4397 new_wp->w_botline = 2; 4422 new_wp->w_botline = 2;
4398 new_wp->w_cursor.lnum = 1; 4423 new_wp->w_cursor.lnum = 1;
4399 #ifdef FEAT_SCROLLBIND 4424 #ifdef FEAT_SCROLLBIND
4400 new_wp->w_scbind_pos = 1; 4425 new_wp->w_scbind_pos = 1;
4401 #endif 4426 #endif
4402 4427
4403 /* We won't calculate w_fraction until resizing the window */ 4428 /* We won't calculate w_fraction until resizing the window */
4404 new_wp->w_fraction = 0; 4429 new_wp->w_fraction = 0;
4405 new_wp->w_prev_fraction_row = -1; 4430 new_wp->w_prev_fraction_row = -1;
4406 4431
4407 #ifdef FEAT_GUI 4432 #ifdef FEAT_GUI
4408 if (gui.in_use) 4433 if (gui.in_use)
4409 { 4434 {
4410 gui_create_scrollbar(&new_wp->w_scrollbars[SBAR_LEFT], 4435 gui_create_scrollbar(&new_wp->w_scrollbars[SBAR_LEFT],
4411 SBAR_LEFT, new_wp); 4436 SBAR_LEFT, new_wp);
4412 gui_create_scrollbar(&new_wp->w_scrollbars[SBAR_RIGHT], 4437 gui_create_scrollbar(&new_wp->w_scrollbars[SBAR_RIGHT],
4413 SBAR_RIGHT, new_wp); 4438 SBAR_RIGHT, new_wp);
4414 } 4439 }
4415 #endif
4416 #ifdef FEAT_EVAL
4417 /* init w: variables */
4418 init_var_dict(&new_wp->w_vars, &new_wp->w_winvar, VAR_SCOPE);
4419 #endif 4440 #endif
4420 #ifdef FEAT_FOLDING 4441 #ifdef FEAT_FOLDING
4421 foldInitWin(new_wp); 4442 foldInitWin(new_wp);
4422 #endif 4443 #endif
4423 #ifdef FEAT_AUTOCMD 4444 #ifdef FEAT_AUTOCMD
4424 unblock_autocmds(); 4445 unblock_autocmds();
4425 #endif 4446 #endif
4426 #ifdef FEAT_SEARCH_EXTRA 4447 #ifdef FEAT_SEARCH_EXTRA
4427 new_wp->w_match_head = NULL; 4448 new_wp->w_match_head = NULL;
4428 new_wp->w_next_match_id = 4; 4449 new_wp->w_next_match_id = 4;
4429 #endif 4450 #endif
4430 }
4431 return new_wp; 4451 return new_wp;
4432 } 4452 }
4433 4453
4434 #if defined(FEAT_WINDOWS) || defined(PROTO) 4454 #if defined(FEAT_WINDOWS) || defined(PROTO)
4435 4455
4486 4506
4487 clear_winopt(&wp->w_onebuf_opt); 4507 clear_winopt(&wp->w_onebuf_opt);
4488 clear_winopt(&wp->w_allbuf_opt); 4508 clear_winopt(&wp->w_allbuf_opt);
4489 4509
4490 #ifdef FEAT_EVAL 4510 #ifdef FEAT_EVAL
4491 vars_clear(&wp->w_vars.dv_hashtab); /* free all w: variables */ 4511 vars_clear(&wp->w_vars->dv_hashtab); /* free all w: variables */
4512 hash_init(&wp->w_vars->dv_hashtab);
4513 unref_var_dict(wp->w_vars);
4492 #endif 4514 #endif
4493 4515
4494 if (prevwin == wp) 4516 if (prevwin == wp)
4495 prevwin = NULL; 4517 prevwin = NULL;
4496 win_free_lsize(wp); 4518 win_free_lsize(wp);