cs136 / seashell

Seashell is an online environment for editing, running, and submitting C programming assignments.
GNU General Public License v3.0
38 stars 19 forks source link

Memory leak not reported #836

Open yc2lee opened 6 years ago

yc2lee commented 6 years ago

The following code generates a memory leak error, which it's supposed to do.

#include <stdlib.h>
#include <stdio.h>

int *f(void) {
  //const unsigned int i = 100;
  int *a = malloc(100);
  return a;
}

int main(void) {
  int *b = f();
  printf("%p\n", b);
  return 0;
}

But if you uncomment the definition of i and use malloc(i), no memory leaks are reported.

The problem is not ASAN parser because the binary executable created by Seashell does not report any errors either.

yc2lee commented 6 years ago

BTW this problem happens on both old and new Seashell versions.

e45lee commented 6 years ago

I suspect the issue is we may be missing a flag that clang passes to cc1 when asan is used.

I think there’s a flag to turn on verbose mode to see what flags are passed to cc1. On Fri, Nov 17, 2017 at 5:00 PM yc2lee notifications@github.com wrote:

BTW this problem happens on both old and new Seashell versions.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cs136/seashell/issues/836#issuecomment-345377387, or mute the thread https://github.com/notifications/unsubscribe-auth/ADK8ihHB1UA0POV9DdtfBHylU97qfh1bks5s3gIPgaJpZM4QfK3K .

e45lee commented 6 years ago

Alright, unfortunately it's not as simple as flag errors. The backend generates code in a way that is slightly different than stock clang (we link all the intermediate LLVM modules together before writing an object file).

Your best bet to fix this is to have the backend write LLVM bitcode to the intermediate object file, instead of writing a standard object file. final_link_step has all the code necessary to do this, as the emscripten version of seashell-clang generates LLVM bitcode files, which is nice, as you can simplify final_link_step. You'll also have to change the extension of the temporary object file to .bc from .o.

Finally, you'll have to set some additional compiler flags and ASAN runtime options as ASan needs some additional help when running with files generated this way. https://github.com/google/sanitizers/issues/647 has the details.

On Thu, Nov 23, 2017 at 4:39 PM, Edward Lee e45lee@uwaterloo.ca wrote:

I suspect the issue is we may be missing a flag that clang passes to cc1 when asan is used.

I think there’s a flag to turn on verbose mode to see what flags are passed to cc1.

On Fri, Nov 17, 2017 at 5:00 PM yc2lee notifications@github.com wrote:

BTW this problem happens on both old and new Seashell versions.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cs136/seashell/issues/836#issuecomment-345377387, or mute the thread https://github.com/notifications/unsubscribe-auth/ADK8ihHB1UA0POV9DdtfBHylU97qfh1bks5s3gIPgaJpZM4QfK3K .

-- Edward Lee