Fix pot. mem leak found by coverity (CID 96004)
authorDaniel Molkentin <danimo@owncloud.com>
Tue, 24 May 2016 09:21:25 +0000 (11:21 +0200)
committerDaniel Molkentin <danimo@owncloud.com>
Tue, 24 May 2016 09:21:33 +0000 (11:21 +0200)
src/3rdparty/certificates/p12topem.cpp

index 75e736a7abf33a7717d1b04acddafebe0c401ac2..bf6a83c4e3eb50be577545adf7ffec555662ec68 100644 (file)
  * \return string PEM
  */
 string x509ToString(BIO *o) {
-    int len = 0;
     BUF_MEM *bptr;
-    void* data;
-    string ret = "";
-    
     BIO_get_mem_ptr(o, &bptr);
-    len = bptr->length;
-    data = calloc(len+10, sizeof(char));
+    int len = bptr->length;
+    void* data = calloc(len+10, sizeof(char));
     BIO_read(o, data, len);
-    ret = strdup((char*)data);
+    string ret = std::string(static_cast<char*>(data));
     free(data);
         
     return ret;