VirtualBox

Changeset 22142 in vbox for trunk/src/VBox/Main/webservice


Ignore:
Timestamp:
Aug 10, 2009 4:17:02 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50912
Message:

Java glue: fixed memory leaks on error path for VDI, make port reusable only certain number of times

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/webservice/glue-jaxws.xsl

    r21899 r22142  
    176176  <xsl:param name="safearray" />
    177177  <xsl:param name="forceelem" />
    178  
     178
    179179  <xsl:variable name="needarray" select="($safearray='yes') and not($forceelem='yes')" />
    180180
     
    213213  <xsl:param name="idltype"/>
    214214  <xsl:param name="safearray"/>
    215   <xsl:variable name="isstruct" 
     215  <xsl:variable name="isstruct"
    216216                select="//interface[@name=$idltype]/@wsmap='struct'" />
    217217  <xsl:choose>
     
    281281               <xsl:value-of select="concat('(', $value, ' != null) ? new ', $gluetype, '(', $value,', port) : null')" />
    282282             </xsl:when>
    283               <xsl:otherwise>             
     283              <xsl:otherwise>
    284284                <!-- if the MOR string is empty, that means NULL, so return NULL instead of an object then -->
    285285                <xsl:value-of select="concat('(', $value, '.length() > 0) ? new ', $gluetype, '(', $value,', port) : null')" />
     
    297297<xsl:template name="genStructWrapper">
    298298  <xsl:param name="ifname" select="@name" />
    299  
     299
    300300  <xsl:value-of select="concat('    private ', $G_virtualBoxPackage,'.',$ifname, ' real;&#10;')"/>
    301301  <xsl:value-of select="'    private VboxPortType port;&#10;&#10;'"/>
     
    306306    <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
    307307    <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
    308     <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>   
     308    <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable>
    309309     <xsl:choose>
    310310       <xsl:when test="$attrreadonly='yes'">
    311311         <xsl:value-of select="concat('&#10;    // read-only attribute ', $ifname, '::', $attrname, ' of type ', $attrtype, '&#10;')" />
    312          
     312
    313313       </xsl:when>
    314314       <xsl:otherwise>
     
    369369
    370370  </xsl:for-each>
    371  
     371
    372372</xsl:template>
    373373
     
    633633    {
    634634        VboxPortType port = null;
     635        int ttl = 0;
     636
    635637        for (VboxPortType cur: known.keySet())
    636638        {
    637             if (known.get(cur) == 0)
     639            int value = known.get(cur);
     640            if ((value & 0x10000) == 0)
    638641            {
    639642                port = cur;
     643                ttl = value & 0xffff;
    640644                break;
    641645            }
     
    653657            }
    654658            port = svc.getVboxServicePort();
     659            // reuse this object 0x10 times
     660            ttl = 0x10;
    655661        }
    656         known.put(port, new Integer(1));
     662        // mark as used
     663        known.put(port, new Integer(0x10000 | ttl));
    657664        return port;
    658665    }
     
    660667    synchronized void releasePort(VboxPortType port)
    661668    {
    662         Integer val =  known.get(port);
     669        Integer val = known.get(port);
    663670        if (val == null || val == 0)
    664671        {
     
    666673            return;
    667674        }
    668         known.put(port, val - 1);
     675
     676        int v = val;
     677        int ttl = v & 0xffff;
     678        // decrement TTL, and throw away port if used too much times
     679        if (--ttl <= 0)
     680        {
     681            known.remove(port);
     682        }
     683        else
     684        {
     685            v = ttl; // set new TTL and clear busy bit
     686            known.put(port, v);
     687        }
    669688    }
    670689}
     
    703722    {
    704723        this.port = pool.getPort();
    705         ((BindingProvider)port).getRequestContext().
    706                 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
     724
     725         try {
     726          ((BindingProvider)port).getRequestContext().
     727                 put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
     728         }  catch (Throwable t) {
     729             if (this.port != null)
     730                pool.releasePort(this.port);
     731             // we have to throw smth derived from RuntimeException
     732             throw new WebServiceException(t);
     733          }
    707734    }
    708735
     
    711738         this.port = pool.getPort();
    712739
    713          ((BindingProvider)port).getRequestContext();
    714          if (requestContext != null)
     740         try {
     741           ((BindingProvider)port).getRequestContext();
     742           if (requestContext != null)
    715743               ((BindingProvider)port).getRequestContext().putAll(requestContext);
    716744
    717          if (responseContext != null)
     745           if (responseContext != null)
    718746               ((BindingProvider)port).getResponseContext().putAll(responseContext);
    719747
    720          ((BindingProvider)port).getRequestContext().
     748           ((BindingProvider)port).getRequestContext().
    721749                put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
     750          } catch (Throwable t) {
     751             if (this.port != null)
     752                pool.releasePort(port);
     753             // we have to throw smth derived from RuntimeException
     754             throw new WebServiceException(t);
     755          }
    722756    }
    723757
     
    726760    {
    727761        logoff(refIVirtualBox);
    728         pool.releasePort(port);
     762        pool.releasePort(this.port);
    729763    }
    730764
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette