199
199
nssCryptokiObject *instance
202
nssCryptokiObject **newInstances = NULL;
202
204
nssPKIObject_Lock(object);
203
205
if (object->numInstances == 0) {
204
object->instances = nss_ZNEWARRAY(object->arena,
206
object->numInstances + 1);
206
newInstances = nss_ZNEWARRAY(object->arena,
208
object->numInstances + 1);
210
PRBool found = PR_FALSE;
209
212
for (i=0; i<object->numInstances; i++) {
210
213
if (nssCryptokiObject_Equal(object->instances[i], instance)) {
211
nssPKIObject_Unlock(object);
212
if (instance->label) {
213
if (!object->instances[i]->label ||
214
!nssUTF8_Equal(instance->label,
215
object->instances[i]->label, NULL))
217
/* Either the old instance did not have a label,
218
* or the label has changed.
220
nss_ZFreeIf(object->instances[i]->label);
221
object->instances[i]->label = instance->label;
222
instance->label = NULL;
224
} else if (object->instances[i]->label) {
225
/* The old label was removed */
226
nss_ZFreeIf(object->instances[i]->label);
227
object->instances[i]->label = NULL;
229
nssCryptokiObject_Destroy(instance);
233
object->instances = nss_ZREALLOCARRAY(object->instances,
235
object->numInstances + 1);
237
if (!object->instances) {
238
nssPKIObject_Unlock(object);
241
object->instances[object->numInstances++] = instance;
219
/* The new instance is identical to one in the array, except
220
* perhaps that the label may be different. So replace
221
* the label in the array instance with the label from the
222
* new instance, and discard the new instance.
224
nss_ZFreeIf(object->instances[i]->label);
225
object->instances[i]->label = instance->label;
226
nssPKIObject_Unlock(object);
227
instance->label = NULL;
228
nssCryptokiObject_Destroy(instance);
231
newInstances = nss_ZREALLOCARRAY(object->instances,
233
object->numInstances + 1);
236
object->instances = newInstances;
237
newInstances[object->numInstances++] = instance;
242
239
nssPKIObject_Unlock(object);
240
return (newInstances ? PR_SUCCESS : PR_FAILURE);
246
243
NSS_IMPLEMENT PRBool