Merge tag 'upstream/3.3.2'
[debian/amanda] / server-src / tapefile.c
index 8e4400bf4a9d49a9a99933661fd80c2bf3c26317..faf58759bb510625a11337a4c8751b035cda8552 100644 (file)
@@ -50,7 +50,7 @@ read_tapelist(
     char *line = NULL;
     int status = 0;
 
-    tape_list = NULL;
+    clear_tapelist();
     if((tapef = fopen(tapefile,"r")) == NULL) {
        if (errno == ENOENT) {
            /* no tapelist is equivalent to an empty tapelist */
@@ -132,6 +132,9 @@ clear_tapelist(void)
     for(tp = tape_list; tp; tp = next) {
        amfree(tp->label);
        amfree(tp->datestamp);
+       amfree(tp->barcode);
+       amfree(tp->meta);
+       amfree(tp->comment);
        next = tp->next;
        amfree(tp);
     }
@@ -275,6 +278,9 @@ remove_tapelabel(
        }
        amfree(tp->datestamp);
        amfree(tp->label);
+       amfree(tp->meta);
+       amfree(tp->comment);
+       amfree(tp->barcode);
        amfree(tp);
     }
 }
@@ -289,7 +295,7 @@ add_tapelabel(
 
     /* insert a new record to the front of the list */
 
-    new = (tape_t *) alloc(SIZEOF(tape_t));
+    new = g_new0(tape_t, 1);
 
     new->datestamp = stralloc(datestamp);
     new->position = 0;
@@ -362,19 +368,17 @@ parse_tapeline(
     int ch;
 
     *status = 0;
-    tp = (tape_t *) alloc(SIZEOF(tape_t));
-
-    tp->prev = NULL;
-    tp->next = NULL;
 
     s = line;
     ch = *s++;
 
     skip_whitespace(s, ch);
     if(ch == '\0') {
-       amfree(tp);
        return NULL;
     }
+
+    tp = g_new0(tape_t, 1);
+
     s1 = s - 1;
     skip_non_whitespace(s, ch);
     s[-1] = '\0';
@@ -409,8 +413,6 @@ parse_tapeline(
        s[-1] = '\0';
        skip_whitespace(s, ch);
        tp->barcode = stralloc(s1);
-    } else {
-       tp->barcode = NULL;
     }
 
     if (strncmp_const(s - 1, "META:") == 0) {
@@ -419,8 +421,6 @@ parse_tapeline(
        s[-1] = '\0';
        skip_whitespace(s, ch);
        tp->meta = stralloc(s1);
-    } else {
-       tp->meta = NULL;
     }
 
     if (strncmp_const(s - 1, "BLOCKSIZE:") == 0) {
@@ -429,13 +429,9 @@ parse_tapeline(
        s[-1] = '\0';
        skip_whitespace(s, ch);
        tp->blocksize = atol(s1);
-    } else {
-       tp->blocksize = 0;
     }
     if (*(s - 1) == '#') {
        tp->comment = stralloc(s); /* skip leading '#' */
-    } else {
-       tp->comment = NULL;
     }
 
     return tp;