Tcl Source Code

Check-in [961337390c]
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: 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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | kennykb-numerics-branch
Files: files | file ages | folders
SHA1: 961337390cc121096a3e25ef6a077cc51f4d56b6
User & Date: dgp 2005-09-23 04:03:43
Context
2005-09-23
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
2005-09-20
14:11
[kennykb-numerics-branch]
* generic/tclExecute.c: Revise TclIncrObj() to call ...
check-in: dd93281cd4 user: dgp tags: kennykb-numerics-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.



















1
2
3
4
5
6
7

















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
14
15
16
17
18
19
20
21
22
23
24
25
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.

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
 * 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.36 2005/09/20 14:11:52 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;
{






|







 







>







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
 * 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;
{

Changes to generic/tclStrToD.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
....
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
 *	interconversion among 'double' and 'mp_int' types.
 *
 * 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: tclStrToD.c,v 1.1.2.37 2005/09/16 19:29:02 dgp Exp $
 *
 *----------------------------------------------------------------------
 */

#include <tclInt.h>
#include <stdio.h>
#include <stdlib.h>
................................................................................
		}
	    }
	    if (octalSignificandOverflow) {
		if (signum) {
		    mp_neg(&octalSignificandBig, &octalSignificandBig);
		}
		TclSetBignumIntRep(objPtr, &octalSignificandBig);
		octalSignificandOverflow = 0;
	    }		
	    break;

	case ZERO:
	case DECIMAL:
	    significandOverflow =
		AccumulateDecimalDigit( 0, numTrailZeros-1,
................................................................................
		}
	    }
	    if (significandOverflow) {
		if (signum) {
		    mp_neg(&significandBig, &significandBig);
		}
		TclSetBignumIntRep(objPtr, &significandBig);
		significandOverflow = 0;
	    }
	    break;

	case FRACTION:
	case EXPONENT:

	    /*






|







 







<







 







<







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1017
1018
1019
1020
1021
1022
1023

1024
1025
1026
1027
1028
1029
1030
....
1070
1071
1072
1073
1074
1075
1076

1077
1078
1079
1080
1081
1082
1083
 *	interconversion among 'double' and 'mp_int' types.
 *
 * 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: tclStrToD.c,v 1.1.2.38 2005/09/23 04:03:43 dgp Exp $
 *
 *----------------------------------------------------------------------
 */

#include <tclInt.h>
#include <stdio.h>
#include <stdlib.h>
................................................................................
		}
	    }
	    if (octalSignificandOverflow) {
		if (signum) {
		    mp_neg(&octalSignificandBig, &octalSignificandBig);
		}
		TclSetBignumIntRep(objPtr, &octalSignificandBig);

	    }		
	    break;

	case ZERO:
	case DECIMAL:
	    significandOverflow =
		AccumulateDecimalDigit( 0, numTrailZeros-1,
................................................................................
		}
	    }
	    if (significandOverflow) {
		if (signum) {
		    mp_neg(&significandBig, &significandBig);
		}
		TclSetBignumIntRep(objPtr, &significandBig);

	    }
	    break;

	case FRACTION:
	case EXPONENT:

	    /*