]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
fix leaks and add saldo entry
authorBastian Dehn <hhaalo@arcor.de>
Sun, 23 Jun 2024 11:55:06 +0000 (13:55 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 23 Jun 2024 11:55:06 +0000 (13:55 +0200)
src/feierabendxml.c
src/time_format.c

index dba4921639b81084d905d180164f67c754bbebda..093df793636fc1511b813ade9a06f341e8aba9c3 100644 (file)
@@ -82,7 +82,7 @@ void writeEntryNode(xmlTextWriterPtr xmlWriter,
        int begin_min,
        int end_hour,
        int end_min,
-       int last_saldo)
+       time_t last_saldo)
 {
        feierabend* fabend = malloc(sizeof(feierabend));
        init_feierabend(fabend);
@@ -344,10 +344,9 @@ void addEntry(int begin_hour,
        int end_min,
        const char* file_path)
 {
-       char* saldo = malloc(sizeof(char) * MAX_STRING_LENGTH);
-       memset(saldo, 0, MAX_STRING_LENGTH);
-
-       readLastSaldo(file_path, saldo);
+       char* saldostr = malloc(sizeof(char) * MAX_STRING_LENGTH);
+       memset(saldostr, 0, MAX_STRING_LENGTH);
+       readLastSaldo(file_path, saldostr);
 
        xmlChar* xmlElemContent = NULL;
        xmlTextWriterPtr xmlwriter = xmlNewTextWriterFilename("/dev/stdout", 0);
@@ -377,6 +376,9 @@ void addEntry(int begin_hour,
                }
        }
 
+       time_t* saldo = malloc(sizeof(time_t));
+       get_seconds_from_string(saldostr, saldo);
+       writeEntryNode(xmlwriter, begin_hour, begin_min, end_hour, end_min, *saldo);
        xmlTextWriterEndElement(xmlwriter);
        xmlTextWriterEndDocument(xmlwriter);
 
@@ -387,8 +389,12 @@ void addEntry(int begin_hour,
        xmlCleanupCharEncodingHandlers();
        xmlDictCleanup();
 
+       free(xmlElemContent);
+       xmlElemContent = NULL;
        free(saldo);
        saldo = NULL;
+       free(saldostr);
+       saldostr = NULL;
 }
 
 int main(int argc, char* argv[])
index 298c5fc76aeef6cc5eb1e4ccc517136306199092..eec05ed1e579bc23547983fd58abb03ed7cd5b23 100644 (file)
@@ -40,14 +40,19 @@ void get_time_str_overtime(time_t timediff, char* timestr)
 
 void get_seconds_from_string(const char* timestr, time_t* seconds)
 {
+       char* first_str_pos = NULL;
        char* str = malloc(sizeof(char) * 7);
        memset(str, 0, 7);
        strncpy(str, timestr, 7);
+       first_str_pos = str;
 
        str = strtok(str, ":");
        *seconds = atol(str) * ONE_HOUR;
        str = strtok(NULL, ":");
        *seconds += atol(str) * 60;
+
+       free(first_str_pos);
+       first_str_pos = NULL;
 }
 
 void get_weekday(int wday, char* weekday)