Detach() first
authorVolker Birk <vb@pep-project.org>
Sun, 31 May 2015 20:04:38 +0200
changeset 40dfb59114debe
parent 39 6fc5cc7a167c
child 41 c55eaabd5ea6
Detach() first
CpEpEngine.cpp
pEp_utitlity.cpp
utf8_helper.cpp
utf8_helper.h
     1.1 --- a/CpEpEngine.cpp	Sun May 31 19:31:19 2015 +0200
     1.2 +++ b/CpEpEngine.cpp	Sun May 31 20:04:38 2015 +0200
     1.3 @@ -117,11 +117,11 @@
     1.4              return FAIL(L"cannot decrypt");
     1.5      }
     1.6  
     1.7 -    *ptext = utf16_bstr(_ptext).Detach();
     1.8 +    *ptext = utf16_bstr(_ptext);
     1.9      pEp_free(_ptext);
    1.10  
    1.11      if (_keylist && _keylist->value)
    1.12 -        *key_list = string_array(_keylist).Detach();
    1.13 +        *key_list = string_array(_keylist);
    1.14      else
    1.15          *key_list = NULL;
    1.16      ::free_stringlist(_keylist);
    1.17 @@ -196,7 +196,7 @@
    1.18      ::pEp_free(_ptext);
    1.19  
    1.20      if (_keylist && _keylist->value)
    1.21 -        *key_list = string_array(_keylist).Detach();
    1.22 +        *key_list = string_array(_keylist);
    1.23      else
    1.24          *key_list = NULL;
    1.25      ::free_stringlist(_keylist);
    1.26 @@ -228,7 +228,7 @@
    1.27      *verify_status = (pEp_STATUS) _status;
    1.28  
    1.29      if (_keylist && _keylist->value)
    1.30 -        *key_list = string_array(_keylist).Detach();
    1.31 +        *key_list = string_array(_keylist);
    1.32      else
    1.33          *key_list = NULL;
    1.34      ::free_stringlist(_keylist);
    1.35 @@ -271,7 +271,7 @@
    1.36      if (_ctext == NULL)
    1.37          return FAIL(L"encrypt_and_sign");
    1.38  
    1.39 -    *ctext = utf16_bstr(_ctext).Detach();
    1.40 +    *ctext = utf16_bstr(_ctext);
    1.41      pEp_free(_ctext);
    1.42  
    1.43      return S_OK;
    1.44 @@ -367,7 +367,7 @@
    1.45          return FAIL(L"trustword");
    1.46      }
    1.47      else {
    1.48 -        *word = utf16_bstr(_word).Detach();
    1.49 +        *word = utf16_bstr(_word);
    1.50          pEp_free(_word);
    1.51          return S_OK;
    1.52      }
    1.53 @@ -422,7 +422,7 @@
    1.54          return FAIL(L"trustwords");
    1.55      }
    1.56      else {
    1.57 -        *words = utf16_bstr(_words).Detach();
    1.58 +        *words = utf16_bstr(_words);
    1.59          pEp_free(_words);
    1.60          return S_OK;
    1.61      }
    1.62 @@ -500,7 +500,7 @@
    1.63      }
    1.64  
    1.65      if (_ident->fpr)
    1.66 -        *fpr = utf16_bstr(_ident->fpr).Detach();
    1.67 +        *fpr = utf16_bstr(_ident->fpr);
    1.68  
    1.69      ::free_identity(_ident);
    1.70  
    1.71 @@ -635,7 +635,7 @@
    1.72          return FAIL(L"find_keys");
    1.73  
    1.74      if (_keylist && _keylist->value) {
    1.75 -        *key_list = string_array(_keylist).Detach();
    1.76 +        *key_list = string_array(_keylist);
    1.77      }
    1.78      else {
    1.79          ::free_stringlist(_keylist);
    1.80 @@ -898,6 +898,8 @@
    1.81      assert(keylist);
    1.82      assert(rating);
    1.83  
    1.84 +    *keylist = NULL;
    1.85 +
    1.86      ::message *_src = text_message_to_C(src);
    1.87      ::message *msg_dst = NULL;
    1.88      ::stringlist_t *_keylist;
    1.89 @@ -912,7 +914,7 @@
    1.90      }
    1.91  
    1.92      if (_keylist) {
    1.93 -        *keylist = string_array(_keylist).Detach();
    1.94 +        *keylist = string_array(_keylist);
    1.95          free_stringlist(_keylist);
    1.96      }
    1.97  
     2.1 --- a/pEp_utitlity.cpp	Sun May 31 19:31:19 2015 +0200
     2.2 +++ b/pEp_utitlity.cpp	Sun May 31 20:04:38 2015 +0200
     2.3 @@ -63,12 +63,12 @@
     2.4              if (_ident == NULL)
     2.5                  throw bad_alloc();
     2.6  
     2.7 -            _ident->address = utf16_bstr(this->address).Detach();
     2.8 +            _ident->address = utf16_bstr(this->address);
     2.9              _ident->comm_type = this->comm_type;
    2.10 -            _ident->fpr = utf16_bstr(this->fpr).Detach();
    2.11 -            _ident->lang = utf16_bstr(this->lang).Detach();
    2.12 -            _ident->username = utf16_bstr(this->username).Detach();
    2.13 -            _ident->user_id = utf16_bstr(this->user_id).Detach();
    2.14 +            _ident->fpr = utf16_bstr(this->fpr);
    2.15 +            _ident->lang = utf16_bstr(this->lang);
    2.16 +            _ident->username = utf16_bstr(this->username);
    2.17 +            _ident->user_id = utf16_bstr(this->user_id);
    2.18  
    2.19              return _ident;
    2.20          }
    2.21 @@ -80,16 +80,16 @@
    2.22              ::memset(ident_s, 0, sizeof(pEp_identity_s));
    2.23              if (ident) {
    2.24                  if (ident->address)
    2.25 -                    ident_s->address = utf16_bstr(ident->address).Detach();
    2.26 +                    ident_s->address = utf16_bstr(ident->address);
    2.27                  if (ident->fpr)
    2.28 -                    ident_s->fpr = utf16_bstr(ident->fpr).Detach();
    2.29 +                    ident_s->fpr = utf16_bstr(ident->fpr);
    2.30                  if (ident->user_id)
    2.31 -                    ident_s->user_id = utf16_bstr(ident->user_id).Detach();
    2.32 +                    ident_s->user_id = utf16_bstr(ident->user_id);
    2.33                  if (ident->username)
    2.34 -                    ident_s->username = utf16_bstr(ident->username).Detach();
    2.35 +                    ident_s->username = utf16_bstr(ident->username);
    2.36                  ident_s->comm_type = (pEp_comm_type) ident->comm_type;
    2.37                  if (ident->lang)
    2.38 -                    ident_s->lang = utf16_bstr(ident->lang).Detach();
    2.39 +                    ident_s->lang = utf16_bstr(ident->lang);
    2.40              }
    2.41          }
    2.42  
    2.43 @@ -157,7 +157,7 @@
    2.44          template<> BSTR from_C< BSTR, char >(char *s)
    2.45          {
    2.46              if (s)
    2.47 -                return utf16_bstr(s).Detach();
    2.48 +                return utf16_bstr(s);
    2.49              else
    2.50                  return _bstr_t(L"").Detach();
    2.51          }
    2.52 @@ -273,8 +273,8 @@
    2.53              msg2->cc = array_from_C<pEp_identity_s, identity_list>(msg->cc);
    2.54              msg2->bcc = array_from_C<pEp_identity_s, identity_list>(msg->bcc);
    2.55              msg2->reply_to = array_from_C<pEp_identity_s, identity_list>(msg->reply_to);
    2.56 -            msg2->references = string_array(msg->references).Detach();
    2.57 -            msg2->keywords = string_array(msg->keywords).Detach();
    2.58 +            msg2->references = string_array(msg->references);
    2.59 +            msg2->keywords = string_array(msg->keywords);
    2.60              msg2->comments = bstr(msg->comments);
    2.61              msg2->opt_fields = array_from_C<opt_field, stringpair_list_t>(msg->opt_fields);
    2.62          }
     3.1 --- a/utf8_helper.cpp	Sun May 31 19:31:19 2015 +0200
     3.2 +++ b/utf8_helper.cpp	Sun May 31 20:04:38 2015 +0200
     3.3 @@ -73,24 +73,24 @@
     3.4              return result;
     3.5          }
     3.6  
     3.7 -        _bstr_t utf16_bstr(string str)
     3.8 +        BSTR utf16_bstr(string str)
     3.9          {
    3.10              wstring wstr = utf16_string(str);
    3.11 -            return _bstr_t(wstr.c_str());
    3.12 +            return _bstr_t(wstr.c_str()).Detach();
    3.13          }
    3.14  
    3.15 -        CComSafeArray<BSTR> string_array(const ::stringlist_t *stringlist)
    3.16 +        LPSAFEARRAY string_array(const ::stringlist_t *stringlist)
    3.17          {
    3.18              int len = ::stringlist_length(stringlist);
    3.19  
    3.20              if (len = 0)
    3.21 -                return CComSafeArray<BSTR>((ULONG)0);
    3.22 +                return NULL;
    3.23  
    3.24              CComSafeArray<BSTR> sa_string_list((LONG) len);
    3.25              LONG n = 0;
    3.26              for (const ::stringlist_t *k = stringlist; k && k->value; k = k->next) {
    3.27                  if (k->value) {
    3.28 -                    HRESULT _result = sa_string_list.SetAt(n, utf16_bstr(k->value).Detach(), false);
    3.29 +                    HRESULT _result = sa_string_list.SetAt(n, utf16_bstr(k->value), false);
    3.30                      assert(_result == S_OK);
    3.31                      if (_result == E_OUTOFMEMORY)
    3.32                          throw std::bad_alloc();
    3.33 @@ -98,7 +98,7 @@
    3.34                  }
    3.35              }
    3.36  
    3.37 -            return sa_string_list;
    3.38 +            return sa_string_list.Detach();
    3.39          }
    3.40  
    3.41          ::stringlist_t * new_stringlist(const SAFEARRAY * safearray)
     4.1 --- a/utf8_helper.h	Sun May 31 19:31:19 2015 +0200
     4.2 +++ b/utf8_helper.h	Sun May 31 20:04:38 2015 +0200
     4.3 @@ -6,8 +6,8 @@
     4.4          std::string utf8_string(std::wstring wstr, NORM_FORM norm = NormalizationC);
     4.5          std::string utf8_string(BSTR bstr, NORM_FORM norm = NormalizationC);
     4.6          std::wstring utf16_string(std::string str);
     4.7 -        _bstr_t utf16_bstr(std::string str);
     4.8 -        ATL::CComSafeArray<BSTR> string_array(const ::stringlist_t *stringlist);
     4.9 +        BSTR utf16_bstr(std::string str);
    4.10 +        LPSAFEARRAY string_array(const ::stringlist_t *stringlist);
    4.11          ::stringlist_t * new_stringlist(const SAFEARRAY * safearray);
    4.12      }
    4.13  }