On Sep 19, 2014, at 6:30 AM, a...@apache.org wrote:

> Repository: trafficserver
> Updated Branches:
>  refs/heads/master a9905459d -> 4a143e584
> 
> 
> TS-2802: Additional fixups.
>         Changed NetVCOptions to use ats_scoped_str instead of a raw pointer.
>         Added comments.
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
> Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/4b48b2c2
> Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/4b48b2c2
> Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/4b48b2c2
> 
> Branch: refs/heads/master
> Commit: 4b48b2c208f7e5607c27653bb407784e2cac1926
> Parents: a990545
> Author: Alan M. Carroll <a...@network-geographics.com>
> Authored: Thu Sep 18 15:45:26 2014 -0500
> Committer: Alan M. Carroll <a...@network-geographics.com>
> Committed: Thu Sep 18 15:45:26 2014 -0500
> 
> ----------------------------------------------------------------------
> iocore/net/I_NetVConnection.h     | 30 ++++++++++++++++++------------
> iocore/net/P_UnixNetVConnection.h |  1 -
> iocore/net/SSLNetVConnection.cc   |  4 ++--
> 3 files changed, 20 insertions(+), 15 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4b48b2c2/iocore/net/I_NetVConnection.h
> ----------------------------------------------------------------------
> diff --git a/iocore/net/I_NetVConnection.h b/iocore/net/I_NetVConnection.h
> index dcf86a7..cf97c64 100644
> --- a/iocore/net/I_NetVConnection.h
> +++ b/iocore/net/I_NetVConnection.h
> @@ -159,7 +159,9 @@ struct NetVCOptions {
> 
>   EventType etype;
> 
> -  char * sni_servername; // SSL SNI to origin
> +  /** Server name to use for SNI data on an outbound connection.
> +   */
> +  ats_scoped_str sni_servername;
> 
>   /// Reset all values to defaults.
>   void reset();
> @@ -167,31 +169,35 @@ struct NetVCOptions {
>   void set_sock_param(int _recv_bufsize, int _send_bufsize, unsigned long 
> _opt_flags,
>                       unsigned long _packet_mark = 0, unsigned long 
> _packet_tos = 0);
> 
> -  NetVCOptions() : sni_servername(NULL) {
> +  NetVCOptions() {
>     reset();
>   }
> 
>   ~NetVCOptions() {
> -    ats_free(sni_servername);
>   }
> 
> -  void set_sni_servername(const char * name, size_t len) {
> +  /** Set the SNI server name.
> +      A local copy is made of @a name.
> +  */
> +  self& set_sni_servername(const char * name, size_t len) {
>     IpEndpoint ip;
> 
> -    ats_free(sni_servername);
> -    sni_servername = NULL;
>     // Literal IPv4 and IPv6 addresses are not permitted in 
> "HostName".(rfc6066#section-3)
>     if (ats_ip_pton(ts::ConstBuffer(name, len), &ip) != 0) {
>       sni_servername = ats_strndup(name, len);
> +    } else {
> +      sni_servername = NULL;
>     }
> +    return *this;
>   }
> 
> -  NetVCOptions & operator=(const NetVCOptions & opt) {
> -    if (&opt != this) {
> -      ats_free(this->sni_servername);
> -      memcpy(this, &opt, sizeof(opt));
> -      if (opt.sni_servername) {
> -        this->sni_servername = ats_strdup(opt.sni_servername);
> +  self& operator=(self const& that) {
> +    if (&that != this) {
> +      sni_servername = NULL; // release any current name.
> +      memcpy(this, &that, sizeof(self));
> +      if (that.sni_servername) {
> +     sni_servername.release(); // otherwise we'll free the source string.


Why don't you want to free the source string in this case?

Reply via email to