(trunk libT) #3956 "tr_bencFree() could be faster" -- fix memory error.
#3956's r11780 has uncovered a longstanding memory error that occurs when tr_bencParse() fails to parse a dict and leaves a dangling key. This is fixed by cleaning up the key.
This commit is contained in:
parent
3f2e8b7b02
commit
ee849ab82b
|
@ -944,14 +944,13 @@ struct SaveNode
|
||||||
static void
|
static void
|
||||||
nodeInitDict( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts )
|
nodeInitDict( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts )
|
||||||
{
|
{
|
||||||
int nKeys;
|
|
||||||
const int n = val->val.l.count;
|
const int n = val->val.l.count;
|
||||||
|
const int nKeys = n / 2;
|
||||||
|
|
||||||
assert( tr_bencIsDict( val ) );
|
assert( tr_bencIsDict( val ) );
|
||||||
|
|
||||||
nKeys = n / 2;
|
|
||||||
node->val = val;
|
node->val = val;
|
||||||
node->children = tr_new0( int, nKeys * 2 );
|
node->children = tr_new0( int, n );
|
||||||
|
|
||||||
if( sort_dicts )
|
if( sort_dicts )
|
||||||
{
|
{
|
||||||
|
@ -974,7 +973,7 @@ nodeInitDict( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int i ;
|
int i;
|
||||||
|
|
||||||
for( i=0; i<n; ++i )
|
for( i=0; i<n; ++i )
|
||||||
node->children[node->childCount++] = i;
|
node->children[node->childCount++] = i;
|
||||||
|
|
Loading…
Reference in New Issue