title: Dynamic/shared library loaded twice / RSA_check_key fails if libcrypto is loaded both statically and dynamically
body: <p><strong>Original Problem:</strong></p>
  
  <p>I currently have a program that loads two shared libraries a.so and b.so dynamically. Both libraries load libcrypto.so (OpenSSL). If the program ends, there is a <code>double free or corrupted error</code>. I already checked my program for errors. Indexes are in bounds, and no dynamic memory is used.</p>
  
  <p>To me it seems as the libcrypto.so library is detached twice at the end of the program. Is there a way to prevent this? Preferably without having to use different instances of libssl, as storage and memory are within close limits.</p>
  
  <p>Im using Ubuntu 14.04 LTS, wrote the libraries in C, and compiled them using gcc with -fpic.</p>
  
  <p>Thanks for your help!</p>
  
  <p>PS: Might be related : <a href="https://stackoverflow.com/questions/11005881/static-library-loaded-twice">Static library loaded twice</a></p>
  
  <p>//Edit: The same problem occurs if a.so and b.so link the libssl statically.</p>
  
  <p>///Edit: The same problem occurs if a.so links statically and b.so links dynamically. (a.so is used first.) If a.so is linked dynamically and b.so statically, an error in libcrypto occurs on <code>RSA_check_key(..)</code>.</p>
  
  <p><strong>Answer</strong></p>
  
  <p>//// Edit: I minimized my code more and found that i was additionally linking something twice statically. This caused the first problem</p>
  
  <p><strong>New Problem:</strong></p>
  
  <p>As mentioned in the second edit, the RSA_check_key fails if libcrypto was linked statically first and then dynamically. Any ideas what happened here?</p>