Убрал утечку памяти
This commit is contained in:
parent
673d0e250d
commit
c6539e2868
4 changed files with 47 additions and 8 deletions
|
@ -1,25 +1,29 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "seagwithsob.h"
|
#include "seagwithsob.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include <stdlib.h>
|
#include "stdlib.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
FILE * file = getFile();
|
FILE * file = getFile();
|
||||||
double * array;
|
double * array;
|
||||||
|
double * orig_arr;
|
||||||
int length;
|
int length;
|
||||||
|
|
||||||
if (file == NULL) return -1;
|
if (file == NULL) return -1;
|
||||||
array = getArray(file);
|
array = getArray(file);
|
||||||
if (array == NULL) return -2;
|
if (array == NULL) return -2;
|
||||||
length = (int)array[0] - 1;
|
length = (int)array[0] - 1;
|
||||||
|
|
||||||
|
orig_arr = array;
|
||||||
array = &array[1];
|
array = &array[1];
|
||||||
printArray(array, length);
|
printArray(array, length);
|
||||||
sort(array, length);
|
sort(array, length);
|
||||||
printArray(array, length);
|
printArray(array, length);
|
||||||
|
|
||||||
|
free(orig_arr);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
randomArray();
|
randomArray();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,43 @@
|
||||||
|
CFLAGS = -mfpmath=sse \
|
||||||
|
-fstack-protector-all \
|
||||||
|
-W \
|
||||||
|
-Wall \
|
||||||
|
-Wextra \
|
||||||
|
-Wunused \
|
||||||
|
-Wcast-align \
|
||||||
|
-Werror \
|
||||||
|
-pedantic \
|
||||||
|
-pedantic-errors \
|
||||||
|
-Wfloat-equal \
|
||||||
|
-Wpointer-arith \
|
||||||
|
-Wformat-security \
|
||||||
|
-Wmissing-format-attribute \
|
||||||
|
-Wformat=1 \
|
||||||
|
-Wwrite-strings \
|
||||||
|
-Wcast-align \
|
||||||
|
-Wno-long-long \
|
||||||
|
-std=gnu99 \
|
||||||
|
-Wstrict-prototypes \
|
||||||
|
-Wmissing-prototypes \
|
||||||
|
-Wmissing-declarations \
|
||||||
|
-Wold-style-definition \
|
||||||
|
-Wdeclaration-after-statement \
|
||||||
|
-Wbad-function-cast \
|
||||||
|
-Wnested-externs \
|
||||||
|
-O3 \
|
||||||
|
-D_DEBUG -g \
|
||||||
|
-c
|
||||||
|
|
||||||
|
|
||||||
all: main.o seagwithsob.o tools.o
|
all: main.o seagwithsob.o tools.o
|
||||||
gcc main.o seagwithsob.o tools.o && rm *.o
|
gcc main.o seagwithsob.o tools.o -lssp && del *.o
|
||||||
./a.out
|
a.exe
|
||||||
|
|
||||||
main.o: main.c
|
main.o: main.c
|
||||||
gcc -c main.c
|
gcc $(CFLAGS) main.c
|
||||||
|
|
||||||
seagwithsob.o: seagwithsob.c
|
seagwithsob.o: seagwithsob.c
|
||||||
gcc -c seagwithsob.c
|
gcc $(CFLAGS) seagwithsob.c
|
||||||
|
|
||||||
tools.o: tools.c
|
tools.o: tools.c
|
||||||
gcc -c tools.c
|
gcc $(CFLAGS) tools.c
|
||||||
|
|
|
@ -28,6 +28,9 @@ void sort(double * array, int length) {
|
||||||
for (int i = index; i < length; ++i) array[i] = zero[i - index];
|
for (int i = index; i < length; ++i) array[i] = zero[i - index];
|
||||||
|
|
||||||
timer += clock();
|
timer += clock();
|
||||||
|
free(zero);
|
||||||
|
free(unit);
|
||||||
|
|
||||||
printf("Required time for sorting is %lf seconds\n", (double)timer / CLOCKS_PER_SEC);
|
printf("Required time for sorting is %lf seconds\n", (double)timer / CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ void randomArray(void) {
|
||||||
sort(array, length);
|
sort(array, length);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printArray(array, length);
|
printArray(array, length);
|
||||||
|
free(array);
|
||||||
} else {
|
} else {
|
||||||
printf("Length not entered!\n");
|
printf("Length not entered!\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue