title: Segfault on accessing the vector<string> of an object populated in shared library
body: <p>I have created a shared libray which just populates the object passed with some hardcoded values from a c++ program.</p>
  <p>On accsing the object data member which is vector I am getting segmentaion fault, alos if i do not access the element still i get sementation fault when the object get destroyed.</p>
  <p>Let me know if any other information related the g++ build version or shared lib build version is required to narrow down the issue.</p>
  <p>Adding one more information I have two machine both ubuntu</p>
  <p><strong>This code works in machine 1</strong></p>
  <pre><code>temp@ubuntu:~/c++$ uname -a
  Linux ubuntu 4.4.0-186-generic #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
  temp@ubuntu:~/c++$ ./a.out
  10.15.29.40
  10.15.29.41
  10.15.29.51
  hostname4
  temp@ubuntu:~/c++$
  </code></pre>
  <p><strong>Machine 2</strong>
  Where as doesn't work in this machine</p>
  <pre><code>temp@ubuntu16:~$ uname -a
  Linux ubuntu16 4.4.0-131-generic #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  temp@ubuntu16:~$ g++ -v
  and the output I have mentione of a.out below
  </code></pre>
  <blockquote>
  <p><strong>Shared library code</strong></p>
  </blockquote>
  <pre><code>#include &lt;filter.h&gt; // has decleration of class Filter
  #ifdef __cplusplus
  extern &quot;C&quot; {
  #endif
  
       int GetFilter(const char* appCtx, Filter&amp; filter)
      {
          int error = -1;
          int success = 0;
  
          filter.a= 10;
          filter.b= 1;
          filter.c= 13;
          filter.d= 524319;
          filter.hostnames.push_back(&quot;10.15.29.40&quot;);
          filter.hostnames.push_back(&quot;10.15.29.41&quot;);
          filter.hostnames.push_back(&quot;10.15.29.51&quot;);
          filter.hostnames.push_back(&quot;hostname4&quot;);
          return success;
      }
  
  #ifdef __cplusplus
  }
  #endif
  </code></pre>
  <blockquote>
  <p><strong>C++ Program</strong></p>
  </blockquote>
  <pre><code>    #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;string&gt;
  #include &lt;stdint.h&gt;
  
  using namespace std;
  // instead of declearing class here filter.h can also be added
  
  class Filter{
  public:
      vector&lt;string&gt; hostnames;
      uint32_t a;
      uint64_t b;
      uint64_t c;
      uint64_t d;
  
  };
  
  extern &quot;C&quot; {
  int GetFilter(const char* name, Filter&amp; filter);
  }
  
  int main() {
          Filter temp;
          GetFilter(&quot;arya&quot; , temp);
          cout&lt;&lt;temp.hostnames.size()&lt;&lt;endl;
          for(int i=0;i&lt;temp.hostnames.size();++i){
                 cout&lt;&lt;temp.hostnames[i]&lt;&lt;endl;
          }
  
          return 0;
  }
  </code></pre>
  <blockquote>
  <p><strong>./a.out output</strong></p>
  </blockquote>
  <pre><code>1   /// &lt;&lt;--- how come size is one??
  10.15.29.40!@⚌⚌⚌{W&gt; 0
  
                       10.15.29.41!⚌{W&gt;⚌⚌ 0
  
                                           10.15.29.511⚌⚌8⚌⚌⚌⚌⚌⚌⚌1                hostname410.15.29.40!@⚌⚌⚌{W&gt; 0
  
                                                                                                                10.15.29.41!⚌{W&gt;⚌⚌ 0
  
                                                                                                                                    10.15.29.511⚌⚌8⚌⚌⚌⚌⚌⚌⚌1    hostname410.15.29.40!@⚌⚌⚌{W&gt; 0
  
                               10.15.29.41!⚌{W&gt;⚌⚌ 0
  
                                                   10.15.29.511⚌⚌8⚌⚌⚌⚌⚌⚌⚌1                hostname410.15.29.40!@⚌⚌⚌{W&gt; 0
  
                                                                                                                        10.15.29.41!⚌{W&gt;⚌⚌ 0
  
                                                                                                                                            10.15.29.511⚌⚌8⚌⚌⚌⚌⚌⚌⚌1             hostname410.15.29.40!@⚌⚌⚌{W&gt; 0
  
                                                10.15.29.41!⚌{W&gt;⚌⚌ 0
  
                                                                    10.15.29.511⚌*** Error in `./a.out': free(): invalid pointer: 0x0000000000de9de8 ***
  ======= Backtrace: =========
  /lib/x86_64-linux-gnu/libc.so.6(+0x777f5)[0x7f5d3e22a7f5]
  /lib/x86_64-linux-gnu/libc.so.6(+0x8038a)[0x7f5d3e23338a]
  /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f5d3e23758c]
  ./a.out[0x4010f1]
  ./a.out[0x401091]
  ./a.out[0x40100a]
  ./a.out[0x400f55]
  ./a.out[0x400e00]
  ./a.out[0x400daa]
  ./a.out[0x400cea]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f5d3e1d3840]
  ./a.out[0x400b59]
  ======= Memory map: ========
  00400000-00402000 r-xp 00000000 fc:00 272871                             /home/virsec/aryaman/a.out
  00601000-00602000 r--p 00001000 fc:00 272871                             /home/virsec/aryaman/a.out
  00602000-00603000 rw-p 00002000 fc:00 272871                             /home/virsec/aryaman/a.out
  00dd8000-00e0a000 rw-p 00000000 00:00 0                                  [heap]
  7f5d38000000-7f5d38021000 rw-p 00000000 00:00 0
  7f5d38021000-7f5d3c000000 ---p 00000000 00:00 0
  7f5d3deaa000-7f5d3dfb2000 r-xp 00000000 fc:00 2753021                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f5d3dfb2000-7f5d3e1b1000 ---p 00108000 fc:00 2753021                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f5d3e1b1000-7f5d3e1b2000 r--p 00107000 fc:00 2753021                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f5d3e1b2000-7f5d3e1b3000 rw-p 00108000 fc:00 2753021                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f5d3e1b3000-7f5d3e373000 r-xp 00000000 fc:00 2752999                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f5d3e373000-7f5d3e573000 ---p 001c0000 fc:00 2752999                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f5d3e573000-7f5d3e577000 r--p 001c0000 fc:00 2752999                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f5d3e577000-7f5d3e579000 rw-p 001c4000 fc:00 2752999                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f5d3e579000-7f5d3e57d000 rw-p 00000000 00:00 0
  7f5d3e57d000-7f5d3e593000 r-xp 00000000 fc:00 2753039                    /lib/x86_64-linux-gnu/libgcc_s.so.1
  7f5d3e593000-7f5d3e792000 ---p 00016000 fc:00 2753039                    /lib/x86_64-linux-gnu/libgcc_s.so.1
  7f5d3e792000-7f5d3e793000 rw-p 00015000 fc:00 2753039                    /lib/x86_64-linux-gnu/libgcc_s.so.1
  7f5d3e793000-7f5d3e905000 r-xp 00000000 fc:00 1572889                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f5d3e905000-7f5d3eb05000 ---p 00172000 fc:00 1572889                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f5d3eb05000-7f5d3eb0f000 r--p 00172000 fc:00 1572889                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f5d3eb0f000-7f5d3eb11000 rw-p 0017c000 fc:00 1572889                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f5d3eb11000-7f5d3eb15000 rw-p 00000000 00:00 0
  7f5d3eb15000-7f5d3eb2a000 r-xp 00000000 fc:00 2753533                    /usr/local/openresty/nginx/libIAE-Assist.so
  7f5d3eb2a000-7f5d3ed29000 ---p 00015000 fc:00 2753533                    /usr/local/openresty/nginx/libIAE-Assist.so
  7f5d3ed29000-7f5d3ed2a000 r--p 00014000 fc:00 2753533                    /usr/local/openresty/nginx/libIAE-Assist.so
  7f5d3ed2a000-7f5d3ed2b000 rw-p 00015000 fc:00 2753533                    /usr/local/openresty/nginx/libIAE-Assist.so
  7f5d3ed2b000-7f5d3ed51000 r-xp 00000000 fc:00 2753071                    /lib/x86_64-linux-gnu/ld-2.23.so
  7f5d3ef42000-7f5d3ef48000 rw-p 00000000 00:00 0
  7f5d3ef4f000-7f5d3ef50000 rw-p 00000000 00:00 0
  7f5d3ef50000-7f5d3ef51000 r--p 00025000 fc:00 2753071                    /lib/x86_64-linux-gnu/ld-2.23.so
  7f5d3ef51000-7f5d3ef52000 rw-p 00026000 fc:00 2753071                    /lib/x86_64-linux-gnu/ld-2.23.so
  7f5d3ef52000-7f5d3ef53000 rw-p 00000000 00:00 0
  7ffe6034f000-7ffe60370000 rw-p 00000000 00:00 0                          [stack]
  7ffe603c5000-7ffe603c8000 r--p 00000000 00:00 0                          [vvar]
  7ffe603c8000-7ffe603ca000 r-xp 00000000 00:00 0                          [vdso]
  ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
  Aborted (core dumped)
  </code></pre>