Fix a long-standing memory leak in the hash table. The leak only appears

following a malloc failure of a hash that copies its keys, which rarely
happens and so we have not previously noticed it. (CVS 3777)

FossilOrigin-Name: 2aae1964572f4d4d1eae090a997e0bd9a82a69b2
This commit is contained in:
drh 2007-03-31 03:59:23 +00:00
parent bf700f3d3d
commit 93553ad05b
3 changed files with 12 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\slarge\smemory\sleak\sin\sthe\sbtree\slayer\nthat\soccurs\sfollowing\san\sI/O\serror\swhen\sin\sshared\scache\smode.\s(CVS\s3776)
D 2007-03-31T02:36:44
C Fix\sa\slong-standing\smemory\sleak\sin\sthe\shash\stable.\s\sThe\sleak\sonly\sappears\nfollowing\sa\smalloc\sfailure\sof\sa\shash\sthat\scopies\sits\skeys,\swhich\srarely\nhappens\sand\sso\swe\shave\snot\spreviously\snoticed\sit.\s(CVS\s3777)
D 2007-03-31T03:59:24
F Makefile.in 2f2c3bf69faf0ae7b8e8af4f94f1986849034530
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -68,7 +68,7 @@ F src/delete.c 151d08386bf9c9e7f92f6b9106c71efec2def184
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c a8740c24af3f39f2d502be1a1c640c96435eaac0
F src/func.c 94372fe3cf26b81d4dcdc15f98ff240c37c8c708
F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
F src/hash.c 67b23e14f0257b69a3e8aa663e4eeadc1a2b6fd5
F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
F src/insert.c aa61e77807becb8b6c3ffcf53be98d20b0e6f107
F src/legacy.c 2631df6a861f830d6b1c0fe92b9fdd745b2c0cd6
@ -447,7 +447,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 6736f4547c0cc2123d1a19ed2d6915712718d22e
R 488be4ffadef0d522e3de226e0170295
P dce4cb84930116db99275f77141fd933bc84288e
R 77a1b633072f6a8b2b599f4a3d3304a7
U drh
Z 940217d7b5c1abc16778694d39dfaa5f
Z cf5aee56787fd88ebb5c4a271134a18c

View File

@ -1 +1 @@
dce4cb84930116db99275f77141fd933bc84288e
2aae1964572f4d4d1eae090a997e0bd9a82a69b2

View File

@ -12,7 +12,7 @@
** This is the implementation of generic hash-tables
** used in SQLite.
**
** $Id: hash.c,v 1.18 2006/02/14 10:48:39 danielk1977 Exp $
** $Id: hash.c,v 1.19 2007/03/31 03:59:24 drh Exp $
*/
#include "sqliteInt.h"
#include <assert.h>
@ -291,7 +291,7 @@ static void removeElementGivenHash(
if( pEntry->count<=0 ){
pEntry->chain = 0;
}
if( pH->copyKey && elem->pKey ){
if( pH->copyKey ){
pH->xFree(elem->pKey);
}
pH->xFree( elem );
@ -378,6 +378,9 @@ void *sqlite3HashInsert(Hash *pH, const void *pKey, int nKey, void *data){
rehash(pH,8);
if( pH->htsize==0 ){
pH->count = 0;
if( pH->copyKey ){
pH->xFree(new_elem->pKey);
}
pH->xFree(new_elem);
return data;
}