From c7c188d7407d1fe27dcae223b5b5977ae27e457f Mon Sep 17 00:00:00 2001 From: kmazouzi Date: Fri, 1 Apr 2016 09:45:00 +0200 Subject: [PATCH] add memory leak --- lab2/memory_access.c | 19 +++++++++++++++++++ lab2/memory_leak.c | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 lab2/memory_access.c create mode 100644 lab2/memory_leak.c diff --git a/lab2/memory_access.c b/lab2/memory_access.c new file mode 100644 index 0000000..2298bce --- /dev/null +++ b/lab2/memory_access.c @@ -0,0 +1,19 @@ + +#include +#include +#define DIM 100 +int main(int argc, char *argv[]) +{ + //float *a; + int i; + float a[DIM]; +// a = (float *) malloc( sizeof(float) * DIM ); + for( i = 0; i < DIM; ++i) a[i] = 0.0; + // sup = k; + // k = a[i]; + a[200] = 99.0; + printf("GOOD END \n"); +// free(a); + return(EXIT_SUCCESS); +} + diff --git a/lab2/memory_leak.c b/lab2/memory_leak.c new file mode 100644 index 0000000..4c09146 --- /dev/null +++ b/lab2/memory_leak.c @@ -0,0 +1,13 @@ +#include +#include +void f(void) +{ + int* x = (int*)malloc(10 * sizeof(int)); + x[9] = 2; +} // problem: memory leak -- x not freed +int main(int argc, char * argv[]) +{ + f(); + printf("GOOD END \n"); + return 0; +} -- 1.7.10.4