diff options
author | Gaspartcho <93390411+Gaspartcho@users.noreply.github.com> | 2024-02-25 23:23:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-25 17:23:28 -0500 |
commit | b4931cb618a2b4d22482694cbc40e60990d684fc (patch) | |
tree | 52abca3095dda3a78f295a997d76d2ab0aadfbc3 | |
parent | 59a4f6f5018a77f12528dd5d21dd7627b39a54a8 (diff) | |
download | lite-xl-plugin-manager-b4931cb618a2b4d22482694cbc40e60990d684fc.tar.gz lite-xl-plugin-manager-b4931cb618a2b4d22482694cbc40e60990d684fc.zip |
hopefully fixed the memory leak (#83)
-rw-r--r-- | lib/microtar/src/microtar.c | 5 | ||||
-rw-r--r-- | src/lpm.c | 11 |
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/microtar/src/microtar.c b/lib/microtar/src/microtar.c index 1cd9920..20c509d 100644 --- a/lib/microtar/src/microtar.c +++ b/lib/microtar/src/microtar.c @@ -337,8 +337,9 @@ int mtar_clear_header(mtar_header_t *h){ h->size = 0; h->mtime = 0; h->type = 0; - bzero(h->name, strlen(h->name)); - bzero(h->linkname, strlen(h->linkname)); + + bzero(h->name, sizeof(h->name)); + bzero(h->linkname, sizeof(h->linkname)); return MTAR_ESUCCESS; } @@ -820,6 +820,9 @@ static int lpm_extract(lua_State* L) { int has_ext_before = 0; int has_ext_allways = 0; + mtar_clear_header(&before_h); + mtar_clear_header(&allways_h); + while ((mtar_read_header(&tar, &h)) != MTAR_ENULLRECORD ) { if (h.type == MTAR_TREG) { @@ -839,7 +842,6 @@ static int lpm_extract(lua_State* L) { return luaL_error(L, "can't extract tar archive file %s, can't create directory %s: %s", src, target, strerror(errno)); } - char buffer[8192]; FILE* file = fopen(target, "wb"); if (!file) { mtar_close(&tar); @@ -848,7 +850,8 @@ static int lpm_extract(lua_State* L) { if (chmod(target, h.mode)) return luaL_error(L, "can't extract tar archive file %s, can't chmod file %s: %s", src, target, strerror(errno)); - + + char buffer[8192]; int remaining = h.size; while (remaining > 0) { int read_size = remaining < sizeof(buffer) ? remaining : sizeof(buffer); @@ -926,7 +929,7 @@ static int lpm_extract(lua_State* L) { if (mtar_read_data(&tar, before_h.name, read_size) != MTAR_ESUCCESS) { mtar_close(&tar); return luaL_error(L, "Error while reading GNU extended: %s", strerror(errno)); - } + } } else if (h.type == MTAR_TGLP) { @@ -936,7 +939,7 @@ static int lpm_extract(lua_State* L) { if (mtar_read_data(&tar, before_h.linkname, read_size) != MTAR_ESUCCESS) { mtar_close(&tar); return luaL_error(L, "Error while reading GNU extended: %s", strerror(errno)); - } + } } mtar_next(&tar); |