summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-04-14 14:44:53 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-04-14 14:58:14 (EDT)
commitf9dafad4a195adec937c72f825aaecdcabfec8d7 (patch)
tree7704d3a7c730f982ae7dcb3c4f670e1389aef99b
parentea566435355699cab1d3db3343cf6996c281f2f2 (diff)
gzip, ustar: Add *_free() functions
-rw-r--r--src/gzip.c10
-rw-r--r--src/gzip.h3
-rw-r--r--src/main.c5
-rw-r--r--src/ustar.c7
-rw-r--r--src/ustar.h3
5 files changed, 22 insertions, 6 deletions
diff --git a/src/gzip.c b/src/gzip.c
index 2596739..dc22ee0 100644
--- a/src/gzip.c
+++ b/src/gzip.c
@@ -71,7 +71,6 @@ opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record)
break;
case OPKG_OPK_ERROR:
default:
- inflateEnd(&gzip->stream);
return OPKG_OPK_ERROR;
}
}
@@ -84,11 +83,16 @@ opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record)
case Z_BUF_ERROR:
break;
case Z_STREAM_END:
- inflateEnd(&gzip->stream);
return OPKG_OPK_END;
default:
- inflateEnd(&gzip->stream);
return OPKG_OPK_ERROR;
}
}
}
+
+void
+opkg_opk_gzip_free(struct opkg_opk_gzip *gzip)
+{
+ inflateEnd(&gzip->stream);
+ free(gzip);
+}
diff --git a/src/gzip.h b/src/gzip.h
index 409de51..73c8340 100644
--- a/src/gzip.h
+++ b/src/gzip.h
@@ -28,4 +28,7 @@ opkg_opk_gzip_init(int (*read)(void *, char **, size_t *), void *user_data);
int
opkg_opk_gzip_read(struct opkg_opk_gzip *gzip, void *record);
+void
+opkg_opk_gzip_free(struct opkg_opk_gzip *gzip);
+
#endif /* OPKG_OPK_GZIP_H_ */
diff --git a/src/main.c b/src/main.c
index 26e60fa..79ed68c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -64,14 +64,15 @@ main(int argc, char *argv[])
}
ustar = opkg_opk_ustar_init(gzip);
if (ustar == NULL) {
- /* TODO: Free gzip. */
+ opkg_opk_gzip_free(gzip);
fclose(file.file);
return EXIT_FAILURE;
}
while ((ret = opkg_opk_ustar_list(ustar, &member)) == OPKG_OPK_OK) {
puts(member.name);
}
- /* TODO: Free ustar and gzip. */
+ opkg_opk_gzip_free(gzip);
+ opkg_opk_ustar_free(ustar);
fclose(file.file);
return EXIT_SUCCESS;
diff --git a/src/ustar.c b/src/ustar.c
index 69071c7..4805880 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -82,7 +82,6 @@ _opkg_opk_ustar_next(struct opkg_opk_ustar *ustar,
}
memset(record, 0, 512);
if (memcmp(header, record, 512) == 0) {
- /* TODO: End gzip stream */
return OPKG_OPK_END;
}
if (memcmp(header->magic, "ustar", strlen("ustar")) != 0) {
@@ -192,3 +191,9 @@ opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size)
}
return OPKG_OPK_OK;
}
+
+void
+opkg_opk_ustar_free(struct opkg_opk_ustar *ustar)
+{
+ free(ustar);
+}
diff --git a/src/ustar.h b/src/ustar.h
index a1c5e75..ccb10a2 100644
--- a/src/ustar.h
+++ b/src/ustar.h
@@ -39,4 +39,7 @@ opkg_opk_ustar_seek(struct opkg_opk_ustar *ustar, const char *member);
int
opkg_opk_ustar_read(struct opkg_opk_ustar *ustar, char *buffer, size_t *size);
+void
+opkg_opk_ustar_free(struct opkg_opk_ustar *ustar);
+
#endif /* OPKG_OPK_USTAR_H_ */