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/XQueryProcessor.cpp
130 130
            it = parameters.find(skey);
131 131
            if (it != parameters.end()) {
132 132
                XdmValue * valuei = it->second;
133
                valuei->decrementRefCount();
134
                if(valuei != nullptr && valuei->getRefCount() < 1){
135
                    delete value;
133
                if(valuei != nullptr) {
134
                    valuei->decrementRefCount();
135
                    if (valuei->getRefCount() < 1) {
136
                        delete value;
137
                    }
138
                    parameters.erase(skey);
139
                    parameters[skey] = value;
136 140
                }
137
                parameters.erase(skey);
138
                parameters[skey] = value;
139 141
            }
140 142
		}
141 143
	} 
......
185 187

  
186 188
    void XQueryProcessor::clearParameters(bool delVal){
187 189
	if(delVal){
188
       		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
189
			XdmValue * value = itr->second;
190
			value->decrementRefCount();
190
       		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
191
                XdmValue *value = itr->second;
192
                if (value != nullptr) {
193
                    value->decrementRefCount();
191 194
#ifdef DEBUG
192
			std::cerr<<"XQueryProc.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
195
                    std::cerr<<"XQueryProc.clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
193 196
#endif
194
			if(value != nullptr && value->getRefCount() < 1){
195
	        		delete value;
196
			}
197
        	}
197
                    if (value->getRefCount() < 1) {
198
                        delete value;
199
                    }
200
                }
201
            }
198 202
		
199 203
	} else {
200 204

  
201 205
		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
202 206
			XdmValue * value = itr->second;
203
			value->decrementRefCount();
204

  
205
        	}
207
			if(value != nullptr) {
208
                value->decrementRefCount();
209
            }
210
		}
206 211
	}
207 212

  
208 213
	parameters.clear();

Also available in: Unified diff