]> gitweb.hhaalo.de Git - discspan.git/commitdiff
fix: struct memory leaks
authorBastian Dehn <hhaalo@arcor.de>
Sun, 25 Jul 2021 19:22:20 +0000 (21:22 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 25 Jul 2021 19:22:20 +0000 (21:22 +0200)
return struct not length of struct

discspan.c
splitter.c
splitter.h

index ec9c7b53d6a241bad191e0f290809f12505394c4..7bb1f70ee00ea54c384af5dc3080ebdacf05c68b 100644 (file)
@@ -11,7 +11,7 @@
 extern void (*printEvent)(const char *output, unsigned long long splitgroesse);
 extern void useage();
 extern file_size_t * read_input_file();
-extern int splitter(file_size_t *input, const char *output,
+extern file_size_t * splitter(file_size_t *input, const char *output,
                        unsigned long long splitgroesse, int length);
 
 int struct_array_length = 0;
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
        int num = 1;
        while (struct_array_length > 0) {
                sprintf(outname, "%s%03d", output, num++);
-               struct_array_length = splitter(fs, outname, split, struct_array_length);
+               fs = splitter(fs, outname, split, struct_array_length);
        }
 
        free(fs);
index 8896f16d9efcda0fa85964d40946e39cb60bd526..e2d7b44dd1ebb1f5c7cc6c0bdd49434a8883222a 100644 (file)
@@ -6,6 +6,8 @@
 #include "discspan.h"
 #include "splitter.h"
 
+extern int struct_array_length;
+
 void writeOutputFile(const char *outputPath, file_size_t *disc, int length)
 {
        FILE *out = fopen(outputPath, "w");
@@ -23,7 +25,7 @@ void onPrintEvent(const char *output, unsigned long long splitgroesse)
                printEvent(output, splitgroesse);
 }
 
-int splitter(file_size_t *input, const char *output,
+file_size_t * splitter(file_size_t *input, const char *output,
                unsigned long long splitgroesse, int length)
 {
        file_size_t *rest = (file_size_t *)
@@ -62,5 +64,6 @@ int splitter(file_size_t *input, const char *output,
 
        free(rest);
        free(disc);
-       return restcount;
+       struct_array_length = restcount;
+       return input;
 }
index bfc7a3df014ed24b7d6b09233f2c5d10d3f596c1..da7f3ae562ea5d83fb73cef534718bf44afeb689 100644 (file)
@@ -21,7 +21,7 @@ void (*printEvent)(const char *output, unsigned long long splitgroesse);
  *
  * @return Restlaenge des neuen Arrays
  */
-int splitter(file_size_t *input, const char *output,
+file_size_t * splitter(file_size_t *input, const char *output,
                unsigned long long splitgroesse, int length);
 
 #endif