Introduce clear_afhi().
authorAndre Noll <maan@systemlinux.org>
Tue, 23 Aug 2011 17:41:27 +0000 (19:41 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 7 Apr 2012 23:21:24 +0000 (01:21 +0200)
aft.c and afh.c contain identical code to free all members of an
instance of struct afh_info. This commit introduces the public
function clear_afhi(), and patches both aft.c and afh.c to call the
new function.

afh.c
afh.h
afh_common.c
aft.c

diff --git a/afh.c b/afh.c
index bc86810..5b1cfe9 100644 (file)
--- a/afh.c
+++ b/afh.c
@@ -204,13 +204,7 @@ int main(int argc, char **argv)
                                print_chunk_table(&afhi);
                        printf("\n");
                }
                                print_chunk_table(&afhi);
                        printf("\n");
                }
-               free(afhi.techinfo);
-               free(afhi.tags.artist);
-               free(afhi.tags.title);
-               free(afhi.tags.year);
-               free(afhi.tags.album);
-               free(afhi.tags.comment);
-               free(afhi.chunk_table);
+               clear_afhi(&afhi);
                ret2 = para_munmap(audio_file_data, audio_file_size);
                if (ret2 < 0 && ret >= 0)
                        ret = ret2;
                ret2 = para_munmap(audio_file_data, audio_file_size);
                if (ret2 < 0 && ret >= 0)
                        ret = ret2;
diff --git a/afh.h b/afh.h
index a574edf..7952809 100644 (file)
--- a/afh.h
+++ b/afh.h
@@ -104,3 +104,4 @@ void afh_get_chunk(long unsigned chunk_num, struct afh_info *afhi,
 void afh_get_header(struct afh_info *afhi, uint8_t audio_format_id,
                void *map, size_t mapsize, char **buf, size_t *len);
 void afh_free_header(char *header_buf, uint8_t audio_format_id);
 void afh_get_header(struct afh_info *afhi, uint8_t audio_format_id,
                void *map, size_t mapsize, char **buf, size_t *len);
 void afh_free_header(char *header_buf, uint8_t audio_format_id);
+void clear_afhi(struct afh_info *afhi);
index 9f1d188..5b6301b 100644 (file)
@@ -221,6 +221,26 @@ success:
        return ret;
 }
 
        return ret;
 }
 
+/**
+ * Deallocate contents of a filled-in ahi structure
+ *
+ * \param afhi The structure to clear.
+ *
+ * The given pointer is kept, everything else is freed.
+ */
+void clear_afhi(struct afh_info *afhi)
+{
+       if (!afhi)
+               return;
+       free(afhi->chunk_table);
+       free(afhi->techinfo);
+       free(afhi->tags.artist);
+       free(afhi->tags.title);
+       free(afhi->tags.year);
+       free(afhi->tags.album);
+       free(afhi->tags.comment);
+}
+
 /**
  * Get the name of the given audio format.
  *
 /**
  * Get the name of the given audio format.
  *
diff --git a/aft.c b/aft.c
index f89235a..7516e32 100644 (file)
--- a/aft.c
+++ b/aft.c
@@ -1914,15 +1914,7 @@ out_free:
                send_ret = sc_send_va_buffer(&pad->cc->scc,
                        "failed to add %s (%s)\n", path, para_strerror(-ret));
        free(obj.data);
                send_ret = sc_send_va_buffer(&pad->cc->scc,
                        "failed to add %s (%s)\n", path, para_strerror(-ret));
        free(obj.data);
-       if (afhi_ptr) {
-               free(afhi_ptr->chunk_table);
-               free(afhi_ptr->techinfo);
-               free(afhi_ptr->tags.artist);
-               free(afhi_ptr->tags.title);
-               free(afhi_ptr->tags.year);
-               free(afhi_ptr->tags.album);
-               free(afhi_ptr->tags.comment);
-       }
+       clear_afhi(afhi_ptr);
        /* Stop adding files only on send errors. */
        return send_ret;
 }
        /* Stop adding files only on send errors. */
        return send_ret;
 }