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/Xslt30Processor.cpp
107 107
            it = parameters.find(skey);
108 108
            if (it != parameters.end()) {
109 109
                XdmValue * valuei = it->second;
110
                valuei->decrementRefCount();
111
                if(valuei != nullptr && valuei->getRefCount() < 1){
112
                    delete value;
110
                if(valuei != nullptr) {
111
                    valuei->decrementRefCount();
112
                    if (valuei->getRefCount() < 1) {
113
                        delete value;
114
                    }
115
                    parameters.erase(skey);
116
                    parameters[skey] = value;
117
                    value->incrementRefCount();
113 118
                }
114
                parameters.erase(skey);
115
                parameters[skey] = value;
116 119
            }
117 120
		}
118 121
	 }
......
136 139

  
137 140

  
138 141
void Xslt30Processor::clearParameters(bool delValues) {
139

  
142
    std::cout<<"clearParameter" <<std::endl;
140 143
	if(delValues){
141
       		for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
142
			
143
			XdmValue * value = itr->second;
144
			value->decrementRefCount();
144
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
145
            XdmValue * value = itr->second;
146
            std::cout<<"clearParameter cp0" <<"ob ref="<<(value)<<std::endl;
147
            if(value != nullptr) {
148
                std::cout<<"clearParameter cp0-1" <<std::endl;
149
                value->decrementRefCount();
145 150
#ifdef DEBUG
146
			std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
151
                std::cout<<"clearParameter() - XdmValue refCount="<<value->getRefCount()<<std::endl;
147 152
#endif
148
			if(value != nullptr && value->getRefCount() < 1){
149
	        		delete value;
150
			}
151
        	}
153
                if (value->getRefCount() < 1) {
154
                    delete value;
155
                }
156
            }
157
            std::cout<<"clearParameter cp0-2" <<std::endl;
158
        }
152 159

  
153 160
	} else {
154
for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
155
		
161
        std::cout<<"clearParameter cp1-0" <<std::endl;
162
        for(std::map<std::string, XdmValue*>::iterator itr = parameters.begin(); itr != parameters.end(); itr++){
163

  
156 164
			XdmValue * value = itr->second;
157
			value->decrementRefCount();
165
            std::cout<<"clearParameter cp1" <<"ob ref="<<(value)<<std::endl;
166

  
167
            if(value == NULL) {
168
                std::cout<<"clearParameter cp1-0 after itr NULL found!!!!!" <<std::endl;
169
            }
170
			if(value != nullptr) {
171
                std::cout<<"clearParameter cp1-1" <<std::endl;
172
                value->decrementRefCount();
173
            }
158 174
		
159 175
        	}
160 176

  
161 177
	}
178
    std::cout<<"clearParameter cp1" <<std::endl;
162 179
	parameters.clear();
180
    std::cout<<"clearParameter cp2" <<std::endl;
163 181

  
164 182
	
165 183
}

Also available in: Unified diff