comparison src/dict.c @ 11142:a54985a73ab2 v8.0.0458

patch 8.0.0458: potential crash if adding list or dict to dict fails commit https://github.com/vim/vim/commit/42f45b850df93b806ef44f3025aecedfffb9ae01 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 14 22:17:14 2017 +0100 patch 8.0.0458: potential crash if adding list or dict to dict fails Problem: Potential crash if adding list or dict to dict fails. Solution: Make sure the reference count is correct. (Nikolai Pavlov, closes #1555)
author Christian Brabandt <cb@256bit.org>
date Tue, 14 Mar 2017 22:30:05 +0100
parents 835604f3c37a
children 162bcd0debd7
comparison
equal deleted inserted replaced
11141:b5ac92d0f31f 11142:a54985a73ab2
354 if (item == NULL) 354 if (item == NULL)
355 return FAIL; 355 return FAIL;
356 item->di_tv.v_lock = 0; 356 item->di_tv.v_lock = 0;
357 item->di_tv.v_type = VAR_LIST; 357 item->di_tv.v_type = VAR_LIST;
358 item->di_tv.vval.v_list = list; 358 item->di_tv.vval.v_list = list;
359 ++list->lv_refcount;
359 if (dict_add(d, item) == FAIL) 360 if (dict_add(d, item) == FAIL)
360 { 361 {
361 dictitem_free(item); 362 dictitem_free(item);
362 return FAIL; 363 return FAIL;
363 } 364 }
364 ++list->lv_refcount;
365 return OK; 365 return OK;
366 } 366 }
367 367
368 /* 368 /*
369 * Add a dict entry to dictionary "d". 369 * Add a dict entry to dictionary "d".
378 if (item == NULL) 378 if (item == NULL)
379 return FAIL; 379 return FAIL;
380 item->di_tv.v_lock = 0; 380 item->di_tv.v_lock = 0;
381 item->di_tv.v_type = VAR_DICT; 381 item->di_tv.v_type = VAR_DICT;
382 item->di_tv.vval.v_dict = dict; 382 item->di_tv.vval.v_dict = dict;
383 ++dict->dv_refcount;
383 if (dict_add(d, item) == FAIL) 384 if (dict_add(d, item) == FAIL)
384 { 385 {
385 dictitem_free(item); 386 dictitem_free(item);
386 return FAIL; 387 return FAIL;
387 } 388 }
388 ++dict->dv_refcount;
389 return OK; 389 return OK;
390 } 390 }
391 391
392 /* 392 /*
393 * Get the number of items in a Dictionary. 393 * Get the number of items in a Dictionary.