2008/11/8 Dominique Pelle <[EMAIL PROTECTED]>:
> Hi
>
> Valgrind memory checker detects mismatches between malloc()/vim_free()
> and alloc()/free in vim-7.2.30:
>
> - If malloc() is used, then free() should be used,
> - if alloc() is used, then vim_free() should be used.
>
> It only really matters when compiling vim with '#define MEM_PROFILE',
> because MEMPROFILE adds one word before each allocated block so
> a mismatch results not only in an illegal free, but also gives incorrect
> memory profile results. Normally MEMPROFILE is not defined, so it's a
> minor bug.
I found a few more of this kind of errors. vim_realloc() should also be
called rather than realloc() when memory was previously allocated
with alloc().
Regards
-- Dominique
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: mbyte.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/mbyte.c,v
retrieving revision 1.70
diff -c -r1.70 mbyte.c
*** mbyte.c 6 Sep 2008 14:44:40 -0000 1.70
--- mbyte.c 8 Nov 2008 05:55:48 -0000
***************
*** 5384,5390 ****
draw_feedback = (char *)alloc(draw_data->chg_first
+ text->length);
else
! draw_feedback = realloc(draw_feedback,
draw_data->chg_first + text->length);
if (draw_feedback != NULL)
{
--- 5384,5390 ----
draw_feedback = (char *)alloc(draw_data->chg_first
+ text->length);
else
! draw_feedback = vim_realloc(draw_feedback,
draw_data->chg_first + text->length);
if (draw_feedback != NULL)
{
Index: gui_w48.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/gui_w48.c,v
retrieving revision 1.43
diff -c -r1.43 gui_w48.c
*** gui_w48.c 24 Jul 2008 18:50:23 -0000 1.43
--- gui_w48.c 8 Nov 2008 05:55:49 -0000
***************
*** 3335,3341 ****
/*
* Convert the string s to the proper format for a filter string by replacing
! * the \t and \n delimeters with \0.
* Returns the converted string in allocated memory.
*
* Keep in sync with convert_filterW() above!
--- 3335,3341 ----
/*
* Convert the string s to the proper format for a filter string by replacing
! * the \t and \n delimiters with \0.
* Returns the converted string in allocated memory.
*
* Keep in sync with convert_filterW() above!
***************
*** 3711,3717 ****
/* The command line is copied to allocated memory, so that we can change
* it. Add the size of the string, the separating NUL and a terminating
* NUL. */
! newcmdline = malloc(STRLEN(cmdline) + STRLEN(progp) + 2);
if (newcmdline == NULL)
return 0;
--- 3711,3717 ----
/* The command line is copied to allocated memory, so that we can change
* it. Add the size of the string, the separating NUL and a terminating
* NUL. */
! newcmdline = (char *)alloc(STRLEN(cmdline) + STRLEN(progp) + 2);
if (newcmdline == NULL)
return 0;
Index: os_vms.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/os_vms.c,v
retrieving revision 1.10
diff -c -r1.10 os_vms.c
*** os_vms.c 6 Aug 2008 16:38:52 -0000 1.10
--- os_vms.c 8 Nov 2008 05:55:49 -0000
***************
*** 381,387 ****
if (--vms_match_free == 0) {
/* add more space to store matches */
vms_match_alloced += EXPL_ALLOC_INC;
! vms_fmatch = (char_u **)realloc(vms_fmatch,
sizeof(char **) * vms_match_alloced);
if (!vms_fmatch)
return 0;
--- 381,387 ----
if (--vms_match_free == 0) {
/* add more space to store matches */
vms_match_alloced += EXPL_ALLOC_INC;
! vms_fmatch = (char_u **)vim_realloc(vms_fmatch,
sizeof(char **) * vms_match_alloced);
if (!vms_fmatch)
return 0;
***************
*** 460,466 ****
if (--files_free < 1)
{
files_alloced += EXPL_ALLOC_INC;
! *file = (char_u **)realloc(*file,
sizeof(char_u **) * files_alloced);
if (*file == NULL)
{
--- 460,466 ----
if (--files_free < 1)
{
files_alloced += EXPL_ALLOC_INC;
! *file = (char_u **)vim_realloc(*file,
sizeof(char_u **) * files_alloced);
if (*file == NULL)
{
Index: misc2.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/misc2.c,v
retrieving revision 1.75
diff -c -r1.75 misc2.c
*** misc2.c 6 Sep 2008 14:44:51 -0000 1.75
--- misc2.c 8 Nov 2008 05:55:52 -0000
***************
*** 873,879 ****
/* 3. check for available memory: call mch_avail_mem() */
if (mch_avail_mem(TRUE) < KEEP_ROOM && !releasing)
{
! vim_free((char *)p); /* System is low... no go! */
p = NULL;
}
else
--- 873,879 ----
/* 3. check for available memory: call mch_avail_mem() */
if (mch_avail_mem(TRUE) < KEEP_ROOM && !releasing)
{
! free((char *)p); /* System is low... no go! */
p = NULL;
}
else