Убрал утечку памяти

This commit is contained in:
AZEN-SGG 2024-11-27 19:02:11 +03:00
parent 673d0e250d
commit c6539e2868
4 changed files with 47 additions and 8 deletions

View file

@ -1,11 +1,12 @@
#include <stdio.h>
#include "seagwithsob.h"
#include "tools.h"
#include <stdlib.h>
#include "stdlib.h"
int main(void) {
FILE * file = getFile();
double * array;
double * orig_arr;
int length;
if (file == NULL) return -1;
@ -13,11 +14,14 @@ int main(void) {
if (array == NULL) return -2;
length = (int)array[0] - 1;
orig_arr = array;
array = &array[1];
printArray(array, length);
sort(array, length);
printArray(array, length);
free(orig_arr);
printf("\n");
randomArray();

View file

@ -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
gcc main.o seagwithsob.o tools.o && rm *.o
./a.out
gcc main.o seagwithsob.o tools.o -lssp && del *.o
a.exe
main.o: main.c
gcc -c main.c
gcc $(CFLAGS) main.c
seagwithsob.o: seagwithsob.c
gcc -c seagwithsob.c
gcc $(CFLAGS) seagwithsob.c
tools.o: tools.c
gcc -c tools.c
gcc $(CFLAGS) tools.c

View file

@ -28,6 +28,9 @@ void sort(double * array, int length) {
for (int i = index; i < length; ++i) array[i] = zero[i - index];
timer += clock();
free(zero);
free(unit);
printf("Required time for sorting is %lf seconds\n", (double)timer / CLOCKS_PER_SEC);
}

View file

@ -64,6 +64,7 @@ void randomArray(void) {
sort(array, length);
printf("\n");
printArray(array, length);
free(array);
} else {
printf("Length not entered!\n");
}