title: How to distinguish between strings in heap or literals?
body: <p>I have a use case where I can get pointers of strings allocated either in memory or literals. Now the latter can't be freed so that's a problem if I pass the wrong one. Is there a way to know which one is allocated and which not?</p>
  
  <pre><code>char *b = "dont free me!";
  if(!IS_LITERAL(b)) {
      free(b);
  }
  </code></pre>
  
  <p>I imagine something like that.</p>
  
  <p>My example:</p>
  
  <p>Scenario 1: literal</p>
  
  <pre><code>char *b = "dont free me!";
  scruct elem* my_element = mylib_create_element(b);
  // do smth
  int result = mylib_destroy_element(my_element); // free literal, very bad
  </code></pre>
  
  <p>Scenario 2: in heap</p>
  
  <pre><code>char *b = malloc(sizeof(char)*17); // example
  strncpy(b, "you can free me!",17);
  
  scruct elem* my_element = mylib_create_element(b);
  // do smth
  int result = mylib_destroy_element(my_element); // free heap, nice
  </code></pre>
  
  <p>How the user calls <code>mylib_create_element(b);</code> is not under my control. If he frees before <code>mylib_destroy_element</code> it can crash. So it has got to be <code>mylib_destroy_element</code> that cleans up.</p>