Index: tree.c =================================================================== RCS file: /cvs/gnome/gnome-xml/tree.c,v retrieving revision 1.214 diff -r1.214 tree.c 4630,4631c4630,4635 < if (def != NULL) < return(def); --- > /* be more paranoid with default and multi prefix namespaces! */ > if ( def != NULL && > ( def->prefix == ns->prefix > || xmlStrEqual( def->prefix, ns->prefix ) ) ) { > return(def); > } 4676a4681 > xmlNsPtr *remNs = NULL; 4680a4686,4689 > > /* helper to remove stale declarations */ > xmlNsPtr curns = NULL, prvns = NULL; > 4709a4719,4727 > remNs = (xmlNsPtr *) xmlMalloc(sizeCache * > sizeof(xmlNsPtr)); > if (remNs == NULL) { > xmlGenericError(xmlGenericErrorContext, > "xmlReconciliateNs : memory pbm\n"); > xmlFree(oldNs); > xmlFree(newNs); > return(-1); > } 4718,4721c4736,4757 < /* < * OK we need to recreate a new namespace definition < */ < n = xmlNewReconciliedNs(doc, tree, node->ns); --- > n = NULL; > > if ( tree->parent != NULL ) { > /* > * check if the namespace is already declared in the > * parent tree > */ > xmlNsPtr def = xmlSearchNsByHref(doc, tree->parent, node->ns->href); > /* be more paranoid with default and multi prefix namespaces! */ > if ( def != NULL ) { > if ( def->prefix == node->ns->prefix > || xmlStrEqual( def->prefix, node->ns->prefix ) ) { > n = def; > } > } > } > if ( n == NULL ) { /* retry with local */ > /* > * OK we need to recreate a new namespace definition > */ > n = xmlNewReconciliedNs(doc, tree, node->ns); > } 4733a4770 > xmlFree(remNs); 4741a4779,4788 > xmlFree(remNs); > return(-1); > } > remNs = (xmlNsPtr *) xmlRealloc(remNs, sizeCache * > sizeof(xmlNsPtr)); > if (remNs == NULL) { > xmlGenericError(xmlGenericErrorContext, > "xmlReconciliateNs : memory pbm\n"); > xmlFree(oldNs); > xmlFree(newNs); 4744a4792,4822 > > /* remove redundant declarations */ > curns = node->nsDef; > remNs[nbCache] = NULL; > while ( curns != NULL ) { > if ( curns != node->ns ) { > prvns = curns; > curns = curns->next; > continue; > } > if ( xmlSearchNsByHref(node->doc, node->parent, n->href) ) { > if ( curns == node->nsDef ) { > node->nsDef = curns->next; > } > else { > prvns->next = curns->next; > } > } > else if ( curns == node->nsDef ) { > n->next = curns->next; > node->nsDef = n; > } > else { > prvns->next = n; > n->next = curns->next; > } > if ( n != curns ) > remNs[nbCache] = curns; > break; > } > 4748c4826 < } --- > } 4750a4829 > 4776a4856,4864 > remNs = (xmlNsPtr *) xmlMalloc(sizeCache * > sizeof(xmlNsPtr)); > if (remNs == NULL) { > xmlGenericError(xmlGenericErrorContext, > "xmlReconciliateNs : memory pbm\n"); > xmlFree(oldNs); > xmlFree(newNs); > return(-1); > } 4785,4788c4873,4893 < /* < * OK we need to recreate a new namespace definition < */ < n = xmlNewReconciliedNs(doc, tree, attr->ns); --- > n = NULL; > if ( tree->parent != NULL ) { > /* > * check if the namespace is already declared in the > * parent tree > */ > xmlNsPtr def = xmlSearchNsByHref(doc, tree->parent, attr->ns->href); > if ( def != NULL ) { > if ( def->prefix == attr->ns->prefix > || xmlStrEqual( def->prefix, attr->ns->prefix ) ) { > n = def; > } > } > } > if ( n == NULL ) { /* retry with local */ > /* > * OK we need to recreate a new namespace definition > */ > n = xmlNewReconciliedNs(doc, tree, attr->ns); > } > /* n = xmlNewReconciliedNs(doc, tree, attr->ns); */ 4800a4906 > xmlFree(remNs); 4808a4915,4924 > xmlFree(remNs); > return(-1); > } > remNs = (xmlNsPtr *) xmlRealloc(remNs, sizeCache * > sizeof(xmlNsPtr)); > if (remNs == NULL) { > xmlGenericError(xmlGenericErrorContext, > "xmlReconciliateNs : memory pbm\n"); > xmlFree(oldNs); > xmlFree(newNs); 4811a4928,4958 > > /* remove redundant declarations */ > curns = node->nsDef; > prvns = NULL; > remNs[nbCache] = NULL; > while ( curns != NULL ) { > if ( curns != attr->ns ) { > prvns = curns; > curns = curns->next; > continue; > } > if ( xmlSearchNsByHref(node->doc, node->parent, n->href) ) { > if ( curns == node->nsDef ) { > node->nsDef = curns->next; > } > else { > prvns->next = curns->next; > } > } > else if ( curns == node->nsDef ) { > n->next = curns->next; > node->nsDef = n; > } > else { > prvns->next = n; > n->next = curns->next; > } > if ( n != curns ) > remNs[nbCache] = curns; > break; > } 4849a4997 > 4853a5002,5011 > > /* drop unused namespaces and avoid memory leaks*/ > if ( remNs!= NULL ) { > for(i=0; i < nbCache; i++) { > if ( remNs[i] != NULL ) { > xmlFreeNs(remNs[i]); > } > } > xmlFree(remNs); > }