Bug Summary

File:src/mite/thread.c
Location:line 58, column 5
Description:Potential leak of memory pointed to by 'mtt'

Annotated Source Code

1/*
2 Teem: Tools to process and visualize scientific data and images .
3 Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago
4 Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann
5 Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public License
9 (LGPL) as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11 The terms of redistributing and/or modifying this software also
12 include exceptions to the LGPL that facilitate static linking.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with this library; if not, write to Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22*/
23
24#include "mite.h"
25#include "privateMite.h"
26
27miteThread *
28miteThreadNew() {
29 static const char me[]="miteThreadNew";
30 miteThread *mtt;
31 int ii;
32
33 mtt = (miteThread *)calloc(1, sizeof(miteThread));
1
Memory is allocated
34 if (!mtt) {
2
Assuming 'mtt' is non-null
3
Taking false branch
35 biffAddf(MITEmiteBiffKey, "%s: couldn't calloc miteThread", me);
36 return NULL((void*)0);
37 }
38
39 mtt->rmop = airMopNew();
40 if (!mtt->rmop) {
4
Taking false branch
41 biffAddf(MITEmiteBiffKey, "%s: couldn't calloc thread's mop", me);
42 airFree(mtt); return NULL((void*)0);
43 }
44 mtt->gctx = NULL((void*)0);
45 mtt->ansScl = mtt->ansVec = mtt->ansTen = NULL((void*)0);
46 mtt->_normal = NULL((void*)0);
47 mtt->shadeVec0 = NULL((void*)0);
48 mtt->shadeVec1 = NULL((void*)0);
49 mtt->shadeScl0 = NULL((void*)0);
50 mtt->shadeScl1 = NULL((void*)0);
51 /* were miteVal a full-fledged gageKind, the following would
52 be done by gagePerVolumeNew */
53 mtt->ansMiteVal = AIR_CALLOC(gageKindTotalAnswerLength(miteValGageKind),(double*)(calloc((gageKindTotalAnswerLength(miteValGageKind))
, sizeof(double)))
54 double)(double*)(calloc((gageKindTotalAnswerLength(miteValGageKind))
, sizeof(double)))
;
55 mtt->directAnsMiteVal = AIR_CALLOC(miteValGageKind->itemMax+1,(double **)(calloc((miteValGageKind->itemMax+1), sizeof(double
*)))
56 double *)(double **)(calloc((miteValGageKind->itemMax+1), sizeof(double
*)))
;
57 if (!(mtt->ansMiteVal && mtt->directAnsMiteVal)) {
5
Taking true branch
58 biffAddf(MITEmiteBiffKey, "%s: couldn't calloc miteVal answer arrays", me);
6
Potential leak of memory pointed to by 'mtt'
59 return NULL((void*)0);
60 }
61 for (ii=0; ii<=miteValGageKind->itemMax; ii++) {
62 mtt->directAnsMiteVal[ii] = mtt->ansMiteVal
63 + gageKindAnswerOffset(miteValGageKind, ii);
64 }
65 mtt->verbose = 0;
66 mtt->skip = 0;
67 mtt->thrid = -1;
68 mtt->ui = mtt->vi = -1;
69 mtt->raySample = 0;
70 mtt->samples = 0;
71 mtt->stage = NULL((void*)0);
72 /* mtt->range[], rayStep, V, RR, GG, BB, TT initialized in
73 miteRayBegin or in miteSample */
74
75 return mtt;
76}
77
78miteThread *
79miteThreadNix(miteThread *mtt) {
80
81 mtt->ansMiteVal = (double *)airFree(mtt->ansMiteVal);
82 mtt->directAnsMiteVal = (double **)airFree(mtt->directAnsMiteVal);
83 airMopOkay(mtt->rmop);
84
85 airFree(mtt);
86 return NULL((void*)0);
87}
88
89/*
90******** miteThreadBegin()
91**
92** this has some of the body of what would be miteThreadInit
93*/
94int
95miteThreadBegin(miteThread **mttP, miteRender *mrr,
96 miteUser *muu, int whichThread) {
97 static const char me[]="miteThreadBegin";
98
99 /* all the miteThreads have already been allocated */
100 (*mttP) = mrr->tt[whichThread];
101
102 if (!whichThread) {
103 /* this is the first thread- it just points to the parent gageContext */
104 (*mttP)->gctx = muu->gctx0;
105 } else {
106 /* we have to generate a new gageContext */
107 (*mttP)->gctx = gageContextCopy(muu->gctx0);
108 if (!(*mttP)->gctx) {
109 biffMovef(MITEmiteBiffKey, GAGEgageBiffKey,
110 "%s: couldn't set up thread %d", me, whichThread);
111 return 1;
112 }
113 }
114
115 if (-1 != mrr->sclPvlIdx) {
116 (*mttP)->ansScl = (*mttP)->gctx->pvl[mrr->sclPvlIdx]->answer;
117 (*mttP)->nPerp = ((*mttP)->ansScl
118 + gageKindAnswerOffset(gageKindScl, gageSclNPerp));
119 (*mttP)->geomTens = ((*mttP)->ansScl
120 + gageKindAnswerOffset(gageKindScl, gageSclGeomTens));
121 } else {
122 (*mttP)->ansScl = NULL((void*)0);
123 (*mttP)->nPerp = NULL((void*)0);
124 (*mttP)->geomTens = NULL((void*)0);
125 }
126 (*mttP)->ansVec = (-1 != mrr->vecPvlIdx
127 ? (*mttP)->gctx->pvl[mrr->vecPvlIdx]->answer
128 : NULL((void*)0));
129 (*mttP)->ansTen = (-1 != mrr->tenPvlIdx
130 ? (*mttP)->gctx->pvl[mrr->tenPvlIdx]->answer
131 : NULL((void*)0));
132 (*mttP)->thrid = whichThread;
133 (*mttP)->raySample = 0;
134 (*mttP)->samples = 0;
135 (*mttP)->verbose = 0;
136 (*mttP)->skip = 0;
137 (*mttP)->_normal = _miteAnswerPointer(*mttP, mrr->normalSpec);
138
139 /* set up shading answers */
140 switch(mrr->shadeSpec->method) {
141 case miteShadeMethodNone:
142 /* nothing to do */
143 break;
144 case miteShadeMethodPhong:
145 (*mttP)->shadeVec0 = _miteAnswerPointer(*mttP, mrr->shadeSpec->vec0);
146 break;
147 case miteShadeMethodLitTen:
148 (*mttP)->shadeVec0 = _miteAnswerPointer(*mttP, mrr->shadeSpec->vec0);
149 (*mttP)->shadeVec1 = _miteAnswerPointer(*mttP, mrr->shadeSpec->vec1);
150 (*mttP)->shadeScl0 = _miteAnswerPointer(*mttP, mrr->shadeSpec->scl0);
151 (*mttP)->shadeScl1 = _miteAnswerPointer(*mttP, mrr->shadeSpec->scl1);
152 break;
153 default:
154 biffAddf(MITEmiteBiffKey, "%s: shade method %d not implemented!",
155 me, mrr->shadeSpec->method);
156 return 1;
157 break;
158 }
159
160 if (_miteStageSet(*mttP, mrr)) {
161 biffAddf(MITEmiteBiffKey, "%s: trouble setting up stage array", me);
162 return 1;
163 }
164 return 0;
165}
166
167int
168miteThreadEnd(miteThread *mtt, miteRender *mrr,
169 miteUser *muu) {
170
171 AIR_UNUSED(mtt)(void)(mtt);
172 AIR_UNUSED(mrr)(void)(mrr);
173 AIR_UNUSED(muu)(void)(muu);
174 return 0;
175}
176