Tcl Source Code

Check-in [112ace53ab]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:
[kennykb-numerics-branch]
* generic/tclStrToD.c: Fixed memory leak. [Bug 1299803]. * generic/tclObj.c:
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | kennykb-numerics-branch
Files: files | file ages | folders
SHA1: 112ace53aba9a840c73e765900fd9ff496289838
User & Date: dgp 2005-09-23 16:13:14
Context
2005-09-23
16:47
[kennykb-numerics-branch]
* unix/Makefile.in: Added -DMP_PREC=4 switch to all c...
check-in: 29be091cd8 user: dgp tags: kennykb-numerics-branch
16:13
[kennykb-numerics-branch]
* generic/tclStrToD.c: Fixed memory leak. [Bug 1299803]...
check-in: 112ace53ab user: dgp tags: kennykb-numerics-branch
04:03
[kennykb-numerics-branch]
* generic/tclStrToD.c: Memory leak. Comment in TclSetBi...
check-in: 961337390c user: dgp tags: kennykb-numerics-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2005-09-23  Don Porter  <[email protected]>

	[kennykb-numerics-branch]

	* generic/tclStrToD.c:	Memory leak.  Comment in TclSetBignumIntRep
	* generic/tclObj.c:	indicates that mp_init() is called on the
	bignumValue argument to clear it, while keeping the digits array
	transferred to the interp of the Tcl_Obj.  The implication is that
	callers of TclSetBignumIntRep() (and their callers) need not call
	mp_clear(), but can imagine they've transferred ownership of an
	mp_int value to Tcl.  However, mp_init() doesn't merely re-initialize
	the fields of an mp_int to hold the value zero.  It also allocates
	a fresh dp array of minimum size governed by MP_PREC.  Without a
	corresponding mp_clear() call somewhere, these dp arrays are leaked.
	Added some mp_clear() calls to fix the leak, but better fix strategies
	should still be pursued.  Perhaps the best approach is to just
	invade the mp_int struct and do the necessary surgery ourselves.

2005-09-20  Don Porter  <[email protected]>

	[kennykb-numerics-branch]
	
	* generic/tclExecute.c:	Revise TclIncrObj() to call
	Tcl_GetBignumAndClearObj.



|
|
<
<
<
<
<
<
<
<
<
<
<







1
2
3
4
5
6











7
8
9
10
11
12
13
2005-09-23  Don Porter  <[email protected]>

	[kennykb-numerics-branch]

	* generic/tclStrToD.c:	Fixed memory leak.  [Bug 1299803].
	* generic/tclObj.c:	












2005-09-20  Don Porter  <[email protected]>

	[kennykb-numerics-branch]
	
	* generic/tclExecute.c:	Revise TclIncrObj() to call
	Tcl_GetBignumAndClearObj.

Changes to generic/tclObj.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928




2929
2930


2931
2932
2933
2934
2935
2936
2937
 * Copyright (c) 1999 by Scriptics Corporation.
 * Copyright (c) 2001 by ActiveState Corporation.
 * Copyright (c) 2005 by Kevin B. Kenny.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclObj.c,v 1.72.2.37 2005/09/23 04:03:43 dgp Exp $
 */

#include "tclInt.h"
#include "tommath.h"
#include <float.h>

#define BIGNUM_AUTO_NARROW 1
................................................................................
    }
  tooLargeForWide:
#endif
#endif
    TclInvalidateStringRep(objPtr);
    TclFreeIntRep(objPtr);
    TclSetBignumIntRep(objPtr, bignumValue);
    mp_clear(bignumValue);
}

void
TclSetBignumIntRep(objPtr, bignumValue)
    Tcl_Obj *objPtr;
    mp_int *bignumValue;
{
    objPtr->typePtr = &tclBignumType;
    PACK_BIGNUM(*bignumValue, objPtr);

    /* Clear the value with mp_init; mp_clear overwrites the digit array. */





    mp_init(bignumValue);


}
 
/*
 *----------------------------------------------------------------------
 *
 * Tcl_DbIncrRefCount --
 *






|







 







<










|
>
>
>
>

|
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
2910
2911
2912
2913
2914
2915
2916

2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
 * Copyright (c) 1999 by Scriptics Corporation.
 * Copyright (c) 2001 by ActiveState Corporation.
 * Copyright (c) 2005 by Kevin B. Kenny.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclObj.c,v 1.72.2.38 2005/09/23 16:13:14 dgp Exp $
 */

#include "tclInt.h"
#include "tommath.h"
#include <float.h>

#define BIGNUM_AUTO_NARROW 1
................................................................................
    }
  tooLargeForWide:
#endif
#endif
    TclInvalidateStringRep(objPtr);
    TclFreeIntRep(objPtr);
    TclSetBignumIntRep(objPtr, bignumValue);

}

void
TclSetBignumIntRep(objPtr, bignumValue)
    Tcl_Obj *objPtr;
    mp_int *bignumValue;
{
    objPtr->typePtr = &tclBignumType;
    PACK_BIGNUM(*bignumValue, objPtr);

    /*
     * Clear the mp_int value.
     * Don't call mp_clear() because it would free the digit array
     * we just packed into the Tcl_Obj.
     */

    bignumValue->dp = NULL;
    bignumValue->alloc = bignumValue->used = 0;
    bignumValue->sign = MP_NEG;
}
 
/*
 *----------------------------------------------------------------------
 *
 * Tcl_DbIncrRefCount --
 *