]> git.donarmstrong.com Git - samtools.git/commitdiff
Tweak order free things (avoids an 'samtools depad' seg fault on error)
authorpeterjc <p.j.a.cock@googlemail.com>
Wed, 20 Jun 2012 15:48:43 +0000 (16:48 +0100)
committerpeterjc <p.j.a.cock@googlemail.com>
Fri, 17 Aug 2012 11:09:50 +0000 (12:09 +0100)
padding.c

index ad8bf5c480d97642dd433ac740059b1d6e45e1e5..fbbb204421f16dfcb6434053d6ef85e729086272 100644 (file)
--- a/padding.c
+++ b/padding.c
@@ -355,7 +355,7 @@ bam_header_t * fix_header(bam_header_t *old, faidx_t *fai)
        if (strlen(header->text) < header->l_text) {
                //fprintf(stderr, "[depad] Reallocating header buffer\n");
                assert (newtext == header->text);
-               newtext = calloc(strlen(header->text) + 1, 1);
+               newtext = malloc(strlen(header->text) + 1);
                strcpy(newtext, header->text);
                free(header->text);
                header->text = newtext;
@@ -439,11 +439,11 @@ int main_pad2unpad(int argc, char *argv[])
 
 depad_end:
        // close files, free and return
-       free(fn_list); free(fn_out);
-        if (h != in->header) bam_header_destroy(h);
+       if (fai) fai_destroy(fai);
+       if (h != in->header) bam_header_destroy(h);
        samclose(in);
        samclose(out);
-       fai_destroy(fai);
+       free(fn_list); free(fn_out);
        return ret;
 }