All pastes #941522 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-03-13 19:20 UTC
rendered paste body
/******************************************************************/
/* Function : _asn1_remove_node                                   */
/* Description: gets free the memory allocated for an NODE_ASN    */
/*              element (not the elements pointed by it).         */
/* Parameters:                                                    */
/*   node: NODE_ASN element pointer.                              */
/******************************************************************/
void
_asn1_remove_node (node_asn * node)
{
  if (node == NULL)
    return;

  if (node->name != NULL)
    _asn1_free (node->name);
  if (node->value != NULL)
    _asn1_free (node->value);
  _asn1_free (node);
}


asn1_delete_structure (ASN1_TYPE * structure)
{
  node_asn *p, *p2, *p3;

  if (*structure == ASN1_TYPE_EMPTY)
    return ASN1_ELEMENT_NOT_FOUND;

  p = *structure;
  while (p)
    {
      if (p->down)
        {
          p = p->down;
        }
      else
        {                       /* no down */
          p2 = p->right;
          if (p != *structure)
            {
              p3 = _asn1_find_up (p);
              _asn1_set_down (p3, p2);
              _asn1_remove_node (p);
              p = p3;
            }
          else
            {                   /* p==root */
              p3 = _asn1_find_left (p);
              if (!p3)
                {
                  p3 = _asn1_find_up (p);
                  if (p3)
                    _asn1_set_down (p3, p2);
                  else
                    {
                      if (p->right)
                        p->right->left = NULL;
                    }
                }
              else
                _asn1_set_right (p3, p2);
              _asn1_remove_node (p);
              p = NULL;
            }
        }
    }

  *structure = ASN1_TYPE_EMPTY;
  return ASN1_SUCCESS;
}