aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-01-22 14:31:13 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-01-22 14:31:13 +0100
commit2135813ebc7cbedb581d6c68865b7177fe4727a2 (patch)
tree0cb56f100247f705d76016e16028ee6645b461a6
parentFix crash. (diff)
downloadcalp-2135813ebc7cbedb581d6c68865b7177fe4727a2.tar.gz
calp-2135813ebc7cbedb581d6c68865b7177fe4727a2.tar.xz
Fixed all leaks.
-rw-r--r--parse.c4
-rw-r--r--trie.inc7
-rw-r--r--vcal.c32
-rw-r--r--vcal.h30
4 files changed, 14 insertions, 59 deletions
diff --git a/parse.c b/parse.c
index 557046b2..66d35a15 100644
--- a/parse.c
+++ b/parse.c
@@ -27,13 +27,12 @@ int parse_file(FILE* f, vcalendar* cal) {
int line = 0;
// TODO these are never freed.
- NEW(vevent, ev, /**/ 100);
+ NEW(vevent, ev);
SNEW(content_line, cline, keylen, vallen);
char c;
while ( (c = fgetc(f)) != EOF) {
- // D E S (-48 '\320')
/*
* A carrige return means that the current line is at an
* end. The following character should always be \n.
@@ -88,6 +87,7 @@ int parse_file(FILE* f, vcalendar* cal) {
LINE(line, cline.key.mem, cline.val.mem);
}
*/
+
handle_kv(cal, ev, &cline, line, &s_ctx);
strbuf_soft_reset(&str);
p_ctx = p_key;
diff --git a/trie.inc b/trie.inc
index a3207bb1..dabd2db8 100644
--- a/trie.inc
+++ b/trie.inc
@@ -5,9 +5,7 @@
#include "err.h"
int CONSTRUCTOR_DECL ( TRIE(TYPE) ) {
- // NEW(TRIE_NODE(TYPE), t, '\0');
- TRIE_NODE(TYPE)* t = malloc(sizeof(*t));
- CONSTRUCT(TRIE_NODE(content_line), t, '\0');
+ NEW(TRIE_NODE(TYPE), t, '\0');
this->root = t;
return 0;
}
@@ -20,8 +18,6 @@ int CONSTRUCTOR_DECL (TRIE_NODE(TYPE), char c) {
return 0;
}
-// int TRIE_NODE_INIT(TYPE) (
-// TRIE_NODE(TYPE)* node,
int CONSTRUCTOR_DECL (TRIE_NODE(TYPE),
char c,
TRIE_NODE(TYPE)* next,
@@ -103,6 +99,7 @@ int TRIE_NODE_FREE(TYPE) ( TRIE_NODE(TYPE)* node ) {
if (node->value != NULL) FFREE(TYPE, node->value);
if (node->next != NULL) TRIE_NODE_FREE(TYPE)(node->next);
if (node->child != NULL) TRIE_NODE_FREE(TYPE)(node->child);
+ free (node);
return 0;
}
diff --git a/vcal.c b/vcal.c
index c751080e..61bf65ce 100644
--- a/vcal.c
+++ b/vcal.c
@@ -7,8 +7,7 @@
#include "trie.inc"
#undef TYPE
-int CONSTRUCTOR_DECL(vevent, int init_size) {
- // HASH_INIT(content_line)(&this->clines, init_size);
+int CONSTRUCTOR_DECL(vevent) {
CONSTRUCT(TRIE(content_line), &this->clines);
return 0;
}
@@ -57,31 +56,8 @@ int FREE_DECL(content_line) {
return 0;
}
-/* TODO reimplement this */
-int copy_vevent(vevent* dest, vevent* src) {
- // strbuf_copy(&dest->dtstart , &src->dtstart);
- // strbuf_copy(&dest->dtend , &src->dtend);
- // strbuf_copy(&dest->summary , &src->summary);
- // strbuf_copy(&dest->description , &src->description);
- return 0;
-}
-
-/* TODO reimplement this */
-int vevent_init_copy(vevent* dest, vevent* src) {
- // strbuf_init_copy(&dest->dtstart , &src->dtstart);
- // strbuf_init_copy(&dest->dtend , &src->dtend);
- // strbuf_init_copy(&dest->summary , &src->summary);
- // strbuf_init_copy(&dest->description , &src->description);
- return 0;
-}
-
-int free_vevent (vevent* ev) {
- // strbuf_free(&ev->dtstart);
- // strbuf_free(&ev->dtend);
- // strbuf_free(&ev->summary);
- // strbuf_free(&ev->description);
- // HASH_FREE(content_line)(&ev->clines);
- TRIE_FREE(content_line)(&ev->clines);
+int FREE_DECL(vevent) {
+ TRIE_FREE(content_line)(&this->clines);
return 0;
}
@@ -109,7 +85,7 @@ int CONSTRUCTOR_DECL(vcalendar) {
int free_vcalendar (vcalendar* cal) {
for (size_t i = 0; i < cal->n_events; i++) {
- free_vevent(cal->events[i]);
+ FFREE(vevent, cal->events[i]);
}
free (cal->events);
return 0;
diff --git a/vcal.h b/vcal.h
index c7bc0cd8..d6218399 100644
--- a/vcal.h
+++ b/vcal.h
@@ -23,26 +23,19 @@ typedef struct {
int param_count;
} content_line;
+int CONSTRUCTOR_DECL(content_line);
+int CONSTRUCTOR_DECL(content_line, int keylen, int vallen);
+
#define TYPE content_line
// #include "hash.h"
#include "trie.h"
#undef TYPE
typedef struct s_vevent {
- /*
- strbuf dtstart;
- strbuf dtend;
- strbuf summary;
- strbuf description;
- */
- // TABLE(content_line) clines;
TRIE(content_line) clines;
} vevent;
-int CONSTRUCTOR_DECL(vevent, int init_size);
-
-int CONSTRUCTOR_DECL(content_line);
-int CONSTRUCTOR_DECL(content_line, int keylen, int vallen);
+int CONSTRUCTOR_DECL(vevent);
int FREE_DECL(content_line);
int content_line_copy (content_line* dest, content_line* src);
@@ -51,18 +44,6 @@ content_line* get_property (vevent* ev, char* key);
int add_content_line (vevent* ev, content_line* c);
-/*
- * Deep copy from src -> dest
- * Requires dest to be initialized beforehand
- * TODO possibly remove this.
- */
-int copy_vevent(vevent* dest, vevent* src);
-
-/*
- * Copies src -> dest, initializing all the strbufs along the way.
- * Requires dest to be initialized.
- */
-int vevent_init_copy(vevent* dest, vevent* src);
int free_vevent(vevent* ev);
typedef struct {
@@ -75,7 +56,8 @@ int CONSTRUCTOR_DECL(vcalendar);
int free_vcalendar (vcalendar* cal);
/*
- * Appends ev to cal. Doesn't copy ev
+ * Appends ev to cal. Doesn't copy ev. So make sure that it wont go
+ * out of scope.
*/
int push_event(vcalendar* cal, vevent* ev);