Commit c7c188d7407d1fe27dcae223b5b5977ae27e457f
1 parent
29b1510128
Exists in
master
add memory leak
Showing 2 changed files with 32 additions and 0 deletions Inline Diff
lab2/memory_access.c
View file @
c7c188d
File was created | 1 | |||
2 | #include <stdlib.h> | |||
3 | #include <stdio.h> | |||
4 | #define DIM 100 | |||
5 | int main(int argc, char *argv[]) | |||
6 | { | |||
7 | //float *a; | |||
8 | int i; | |||
9 | float a[DIM]; | |||
10 | // a = (float *) malloc( sizeof(float) * DIM ); | |||
11 | for( i = 0; i < DIM; ++i) a[i] = 0.0; | |||
12 | // sup = k; | |||
13 | // k = a[i]; | |||
14 | a[200] = 99.0; | |||
15 | printf("GOOD END \n"); | |||
16 | // free(a); | |||
17 | return(EXIT_SUCCESS); |
lab2/memory_leak.c
View file @
c7c188d
File was created | 1 | #include <stdlib.h> | ||
2 | #include <stdio.h> | |||
3 | void f(void) | |||
4 | { | |||
5 | int* x = (int*)malloc(10 * sizeof(int)); | |||
6 | x[9] = 2; | |||
7 | } // problem: memory leak -- x not freed | |||
8 | int main(int argc, char * argv[]) | |||
9 | { | |||
10 | f(); | |||
11 | printf("GOOD END \n"); | |||
12 | return 0; | |||
13 | } |