Project

Profile

Help

Revision 146cfacb

Added by O'Neil Delpratt 5 months ago

Saxon/C memory management patches

View differences:

src/main/c/Saxon.C.API/XsltProcessor.cpp
129 129
            it = parameters.find(skey);
130 130
            if (it != parameters.end()) {
131 131
                XdmValue * valuei = it->second;
132
                valuei->decrementRefCount();
133
                if(valuei != nullptr && valuei->getRefCount() < 1){
134
                    delete value;
132
                if(valuei != nullptr) {
133
                    valuei->decrementRefCount();
134
                    if (valuei->getRefCount() < 1) {
135
                        delete value;
136
                    }
137
                    parameters.erase(skey);
138
                    parameters[skey] = value;
135 139
                }
136
                parameters.erase(skey);
137
                parameters[skey] = value;
138 140
            }
139 141
		}
140 142
	} 
......
183 185

  
184 186
void XsltProcessor::clearParameters(bool delValues) {
185 187
	if(delValues){
186
       		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
187
			
188
			XdmValue * value = itr->second;
189
			value->decrementRefCount();
188
       		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
189

  
190
                XdmValue *value = itr->second;
191
                if (value != nullptr) {
192
                    value->decrementRefCount();
190 193
#ifdef DEBUG
191
			std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
194
                    std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
192 195
#endif
193
			if(value != nullptr && value->getRefCount() < 1){
194
	        		delete value;
195
			}
196
        	}
196
                    if (value->getRefCount() < 1) {
197
                        delete value;
198
                    }
199
                }
200
            }
197 201
		
198 202
	} else {
199
for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
203
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
200 204
		
201 205
			XdmValue * value = itr->second;
202
			value->decrementRefCount();
206
			if(value != nullptr) {
207
                value->decrementRefCount();
208
            }
203 209
		
204
        	}
210
        }
205 211

  
206 212
	}
207 213
	parameters.clear();

Also available in: Unified diff