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/XsltExecutable.cpp
81 81

  
82 82
        XdmValue *valuei = paramIter->second;
83 83
        if (valuei == nullptr) {
84
            std::cerr << "Error in XsltExecutable copy constructor" << std::endl;
84
            std::cerr << "Error in XsltExecutable copy constructor - parameter value is NULL" << std::endl;
85 85
        } else {
86 86
            parameters[paramIter->first] = new XdmValue(*(valuei));
87 87
        }
......
126 126
    if (_selection != nullptr) {
127 127
        _selection->incrementRefCount();
128 128
        selectionV = _selection;
129
        selection = _selection->getUnderlyingValue();
129
        selection = SaxonProcessor::sxn_environ->env->NewGlobalRef(_selection->getUnderlyingValue());
130 130
    }
131 131
}
132 132

  
......
160 160
            it = parameters.find(skey);
161 161
            if (it != parameters.end()) {
162 162
                XdmValue *valuei = it->second;
163
                valuei->decrementRefCount();
164
                if (valuei != nullptr && valuei->getRefCount() < 1) {
165
                    delete value;
163
                if(valuei != nullptr) {
164
                    valuei->decrementRefCount();
165
                    if (valuei->getRefCount() < 1) {
166
                        delete value;
167
                    }
168
                    parameters.erase(skey);
169
                    parameters[skey] = value;
166 170
                }
167
                parameters.erase(skey);
168
                parameters[skey] = value;
169 171
            }
170 172
        }
171 173
    }
......
243 245
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
244 246

  
245 247
            XdmValue *value = itr->second;
246
            value->decrementRefCount();
248
            if(value != nullptr) {
249
                value->decrementRefCount();
247 250
#ifdef DEBUG
248
            std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
251
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
249 252
#endif
250
            if (value != nullptr && value->getRefCount() < 1) {
251
                delete value;
253
                if (value->getRefCount() < 1) {
254
                    delete value;
255
                }
252 256
            }
253 257
        }
254 258

  
......
258 262
        for (std::map<std::string, XdmValue *>::iterator itr = parameters.begin(); itr != parameters.end(); itr++) {
259 263

  
260 264
            XdmValue *value = itr->second;
261
            value->decrementRefCount();
265
            if(value != nullptr) {
266
                value->decrementRefCount();
267
            }
262 268

  
263 269
        }
264 270

  

Also available in: Unified diff