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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
diff -ur otcl-1.11/otcl.c otcl-1.11.new/otcl.c
--- otcl-1.11/otcl.c 2004-01-05 16:56:07.000000000 -0800
+++ otcl-1.11.new/otcl.c 2004-01-13 04:12:10.000000000 -0800
@@ -290,7 +290,7 @@
if (!l) return 0;
if (l->cl == s) {
*sl = l->next;
- ckfree((char*)l);
+ ckfree((char*)l); l = NULL;
return 1;
}
while (l->next && l->next->cl != s) l = l->next;
@@ -442,7 +442,7 @@
old_args2, argv[1], in->errorLine);
compat_Tcl_AddObjErrorInfo(in, msg, -1);
}
- if (argc+2 > OTCLSMALLARGS) { ckfree((char*)args); args = 0; }
+ if (argc+2 > OTCLSMALLARGS) { ckfree((char*)args); args = NULL; }
return result;
}
@@ -479,7 +479,7 @@
cl ? args[2] : argv[0], in->errorLine);
compat_Tcl_AddObjErrorInfo(in, msg, -1);
}
- if (argc+3 > OTCLSMALLARGS) { ckfree((char*)args); args = 0; }
+ if (argc+3 > OTCLSMALLARGS) { ckfree((char*)args); args = NULL; }
return result;
}
@@ -500,7 +500,7 @@
static void
AutoLoaderDP(ClientData cd) {
- ckfree((char*)cd);
+ ckfree((char*)cd); cd = NULL;
}
static int
@@ -579,8 +579,8 @@
Tcl_HashEntry *hPtr = Tcl_FindHashEntry(methods, nm);
if (hPtr != 0) {
Tcl_CmdInfo* co = (Tcl_CmdInfo*)Tcl_GetHashValue(hPtr);
- if (co->deleteProc != 0) (*co->deleteProc)(co->deleteData);
- ckfree((char*)co);
+ if (co->deleteProc != 0) { (*co->deleteProc)(co->deleteData); } co->deleteProc = NULL;
+ ckfree((char*)co); co = NULL;
Tcl_DeleteHashEntry(hPtr);
return 1;
}
@@ -614,7 +614,7 @@
(Tcl_Namespace*)NULL, 0);
if (cmd)
Tcl_DeleteCommandFromToken(pdpd->interp, cmd);
- ckfree((char*)pdpd);
+ ckfree((char*)pdpd); pdpd = NULL;
}
#endif
@@ -674,7 +674,7 @@
for (i = 0; i < argc; i++)
Tcl_DecrRefCount(objv[i]);
- ckfree((char *)objv);
+ ckfree((char *)objv); objv = NULL;
#else /* TCL_MAJOR_VERSION < 8 */
@@ -691,7 +691,7 @@
#endif /* TCL_MAJOR_VERSION < 8 */
- ckfree((char*)nargs);
+ ckfree((char*)nargs); nargs = NULL;
argv[1] = name;
argv[2] = oargs;
@@ -926,7 +926,7 @@
static void
PrimitiveODestroy(ClientData cd) {
PrimitiveODestroyNoFree(cd);
- ckfree((char*)cd);
+ ckfree((char*)cd); cd = NULL;
}
static void
@@ -1002,18 +1002,18 @@
Tcl_CmdInfo* co = (Tcl_CmdInfo*)Tcl_GetHashValue(hp2);
ClientData cdest = cd;
if (co->clientData != 0) cdest = co->clientData;
- if (co->deleteProc != 0) (*co->deleteProc)(co->deleteData);
- ckfree((char*)co);
+ if (co->deleteProc != 0) { (*co->deleteProc)(co->deleteData); } co->deleteProc = NULL;
+ ckfree((char*)co); co = NULL;
}
if (obj->procs) {
- Tcl_DeleteHashTable(obj->procs); ckfree((char*)(obj->procs));
+ Tcl_DeleteHashTable(obj->procs); ckfree((char*)(obj->procs)); obj->procs = NULL;
}
(void)RemoveInstance(obj, obj->cl);
#if TCL_MAJOR_VERSION >= 8
- ckfree((char*)(obj->variables.procPtr));
- ckfree((char*)(obj->variables.varTablePtr));
+ ckfree((char*)(obj->variables.procPtr)); obj->variables.procPtr = NULL;
+ ckfree((char*)(obj->variables.varTablePtr)); obj->variables.varTablePtr = NULL;
#endif
}
@@ -1035,8 +1035,7 @@
obj->id = Tcl_CreateCommand(in, name, OTclDispatch, (ClientData)obj,
PrimitiveODestroy);
} else {
- ckfree((char *)obj);
- obj = NULL;
+ ckfree((char *)obj); obj = NULL;
}
#endif
return obj;
@@ -1123,14 +1122,14 @@
Tcl_CmdInfo* co = (Tcl_CmdInfo*)Tcl_GetHashValue(hPtr);
ClientData cdest = cd;
if (co->clientData != 0) cdest = co->clientData;
- if (co->deleteProc != 0) (*co->deleteProc)(co->deleteData);
- ckfree((char*)co);
+ if (co->deleteProc != 0) { (*co->deleteProc)(co->deleteData); } co->deleteProc = NULL;
+ ckfree((char*)co); co = NULL;
}
Tcl_DeleteHashTable(&cl->instprocs);
if (cl->objectdata) {
Tcl_DeleteHashTable(cl->objectdata);
- ckfree((char*)(cl->objectdata)); cl->objectdata = 0;
+ ckfree((char*)(cl->objectdata)); cl->objectdata = NULL;
}
/*
@@ -1151,7 +1150,7 @@
* PrimitiveODestory to destory the hash entries first */
PrimitiveODestroyNoFree(cd);
Tcl_DeleteHashTable(&cl->instances);
- ckfree((char*)cd);
+ ckfree((char*)cd); cd = NULL;
}
@@ -1176,8 +1175,7 @@
obj->id = Tcl_CreateCommand(in, name, OTclDispatch, (ClientData)cl,
PrimitiveCDestroy);
} else {
- ckfree((char *)cl);
- cl = NULL;
+ ckfree((char *)cl); cl = NULL;
}
#endif
return cl;
@@ -1359,6 +1357,9 @@
OTclObject* obj = OTclAsObject(in, cd);
Tcl_CmdInfo proc;
int op;
+ // NULL out the deleteProc value
+ // as it may be filled with random data on variable creation
+ proc.deleteProc = NULL; proc.deleteData = NULL;
if (!obj) return OTclErrType(in, argv[0], "Object");
if (argc != 7) return OTclErrArgCnt(in,argv[0],"proc name args body");
@@ -1488,7 +1489,7 @@
Tcl_AppendResult(in, "expected ?inst/local? or ?inst? ?local? but got ",
argv[i]);
}
- ckfree((char*)av);
+ ckfree((char*)av); av = NULL;
if (result != TCL_OK) break;
}
return result;
@@ -1594,10 +1595,10 @@
scl[i] = OTclGetClass(in, av[i]);
loaded = (scl[i] != 0);
}
- ckfree(args);
+ ckfree(args); args = NULL;
if (!loaded) {
- ckfree((char*)av);
- ckfree((char*)scl);
+ ckfree((char*)av); av = NULL;
+ ckfree((char*)scl); scl = NULL;
return OTclErrBadVal(in, "a list of classes", argv[4]);
}
}
@@ -1621,8 +1622,8 @@
}
if (reversed != 0) {
- ckfree((char*)av);
- ckfree((char*)scl);
+ ckfree((char*)av); av = NULL;
+ ckfree((char*)scl); scl = NULL;
return OTclErrBadVal(in, "classes in dependence order", argv[4]);
}
@@ -1641,8 +1642,8 @@
}
for (i = 0; i < ac; i++)
AddSuper(cl, scl[i]);
- ckfree((char*)av);
- ckfree((char*)scl);
+ ckfree((char*)av); av = NULL;
+ ckfree((char*)scl); scl = NULL;
FlushPrecedences(cl);
if (!ComputePrecedence(cl)) {
@@ -1784,17 +1785,25 @@
OTclClass* cl = OTclAsClass(in, cd);
Tcl_CmdInfo proc;
int op;
+ // NULL out the deleteProc value
+ // as it may be filled with random data on variable creation
+ proc.deleteProc = NULL; proc.deleteData = NULL;
if (!cl) return OTclErrType(in, argv[0], "Class");
if (argc != 7) return OTclErrArgCnt(in,argv[0],"instproc name args body");
+
/*
* if the args list is "auto", the body is a script to load the proc
*/
- if (!strcmp("auto", argv[5])) op = MakeAuto(&proc, argv[6]);
- else if (argv[5][0]==0 && argv[6][0]==0) op = -1;
- else op = MakeProc(&proc,in, argc-3, argv+3);
+ if (!strcmp("auto", argv[5])) {
+ op = MakeAuto(&proc, argv[6]);
+ } else if (argv[5][0]==0 && argv[6][0]==0) {
+ op = -1;
+ } else {
+ op = MakeProc(&proc,in, argc-3, argv+3);
+ }
(void)RemoveMethod(&cl->instprocs, argv[4], (ClientData)cl);
if (op == 1) AddMethod(&cl->instprocs, argv[4], proc.proc,
|