#include <glib/gmessages.h>
#include <ctype.h>
#include "../cabinet.h"
+#include "../cabinet-memory.h"
#include "cabextract.h"
#ifdef DEBUG
/* generic stuff */
-#define CAB(x) (decomp_state.x)
-#define ZIP(x) (decomp_state.methods.zip.x)
-#define QTM(x) (decomp_state.methods.qtm.x)
-#define LZX(x) (decomp_state.methods.lzx.x)
+#define decomp_state_ptr ((struct decomp_state *)acquire_cabinet_memory_data_get(sizeof(struct decomp_state)))
+#define CAB(x) (decomp_state_ptr->x)
+#define ZIP(x) (decomp_state_ptr->methods.zip.x)
+#define QTM(x) (decomp_state_ptr->methods.qtm.x)
+#define LZX(x) (decomp_state_ptr->methods.lzx.x)
#define DECR_OK (0)
#define DECR_DATAFORMAT (1)
#define DECR_ILLEGALDATA (2)
#define CAB_BLOCKMAX (32768)
#define CAB_INPUTMAX (CAB_BLOCKMAX+6144)
-static struct {
+struct decomp_state {
struct folder *current; /* current folder we're extracting from */
ULONG offset; /* uncompressed offset within folder */
UBYTE *outpos; /* (high level) start of data to use up */
struct QTMstate qtm;
struct LZXstate lzx;
} methods;
-} decomp_state;
+};
/* MSZIP decruncher */
while (p != (struct Ziphuft *)NULL)
{
q = (--p)->v.t;
- free(p);
+ acquire_cabinet_memory_free(p);
p = q;
}
}
l[h] = j; /* set table size in stack */
/* allocate and link in new table */
- if (!(q = (struct Ziphuft *) malloc((z + 1)*sizeof(struct Ziphuft))))
+ if (!(q = (struct Ziphuft *) acquire_cabinet_memory_malloc((z + 1)*sizeof(struct Ziphuft))))
{
if(h)
Ziphuft_free(ZIP(u)[0]);
/* if a previously allocated window is big enough, keep it */
if (window < 10 || window > 21) return DECR_DATAFORMAT;
if (QTM(actual_size) < (ULONG)wndsize) {
- if (QTM(window)) free(QTM(window));
+ if (QTM(window)) acquire_cabinet_memory_free(QTM(window));
QTM(window) = NULL;
}
if (!QTM(window)) {
- if (!(QTM(window) = malloc(wndsize))) return DECR_NOMEMORY;
+ if (!(QTM(window) = acquire_cabinet_memory_malloc(wndsize))) return DECR_NOMEMORY;
QTM(actual_size) = wndsize;
}
QTM(window_size) = wndsize;
/* if a previously allocated window is big enough, keep it */
if (window < 15 || window > 21) return DECR_DATAFORMAT;
if (LZX(actual_size) < wndsize) {
- if (LZX(window)) free(LZX(window));
+ if (LZX(window)) acquire_cabinet_memory_free(LZX(window));
LZX(window) = NULL;
}
if (!LZX(window)) {
- if (!(LZX(window) = malloc(wndsize))) return DECR_NOMEMORY;
+ if (!(LZX(window) = acquire_cabinet_memory_malloc(wndsize))) return DECR_NOMEMORY;
LZX(actual_size) = wndsize;
}
LZX(window_size) = wndsize;
char c, *s, *d, *name;
int ok = 0;
- if (!(name = malloc(strlen(fi->filename) + (dir ? strlen(dir) : 0) + 2))) {
+ if (!(name = acquire_cabinet_memory_malloc(strlen(fi->filename) + (dir ? strlen(dir) : 0) + 2))) {
g_warning(_("out of memory!"));
return 0;
}
}
/* as full filename is no longer needed, free it */
- free(name);
+ acquire_cabinet_memory_free(name);
if (!ok) {
perror(fi->filename);
UBYTE *buf = NULL;
do {
if (len > maxlen) len = maxlen;
- if (!(buf = realloc(buf, (size_t) len))) break;
+ if (!(buf = acquire_cabinet_memory_realloc(buf, (size_t) len))) break;
if (!cabinet_read(cab, buf, (size_t) len)) break;
/* search for a null terminator in what we've just read */
} while (!ok);
if (!ok) {
- if (buf) free(buf); else g_warning(_("out of memory!"));
+ if (buf) acquire_cabinet_memory_free(buf); else g_warning(_("out of memory!"));
return NULL;
}
if (!cabinet_read(cab, buf, cffold_SIZEOF)) return 0;
if (folder_resv) cabinet_skip(cab, folder_resv);
- fol = (struct folder *) calloc(1, sizeof(struct folder));
+ fol = (struct folder *) acquire_cabinet_memory_malloc0(sizeof(struct folder));
if (!fol) { g_warning(_("out of memory!")); return 0; }
fol->cab[0] = cab;
/* read files */
for (i = 0; i < num_files; i++) {
if (!cabinet_read(cab, buf, cffile_SIZEOF)) return 0;
- file = (struct file *) calloc(1, sizeof(struct file));
+ file = (struct file *) acquire_cabinet_memory_malloc0(sizeof(struct file));
if (!file) { g_warning(_("out of memory!")); return 0; }
file->length = EndGetI32(buf+cffile_UncompressedSize);
* otherwise.
*/
static struct cabinet *load_cab_offset(struct acquire_cabinet *acquire_cabinet, off_t offset) {
- struct cabinet *cab = (struct cabinet *) calloc(1, sizeof(struct cabinet));
+ struct cabinet *cab = (struct cabinet *) acquire_cabinet_memory_malloc0(sizeof(struct cabinet));
int ok;
if (!cab) return NULL;
/* cabinet_close(cab); * CAPTIVE */
if (ok) return cab;
- free(cab);
+ acquire_cabinet_memory_free(cab);
return NULL;
}
int state = 0, found = 0, ok = 0;
/* open the file and search for cabinet headers */
- if ((cab = (struct cabinet *) calloc(1, sizeof(struct cabinet)))) {
+ if ((cab = (struct cabinet *) acquire_cabinet_memory_malloc0(sizeof(struct cabinet)))) {
cab->acquire_cabinet = acquire_cabinet;
cab->filename = acquire_cabinet->filename;
cab->filelen = acquire_cabinet->size;
}
/* cabinet_close(cab); * CAPTIVE */
}
- free(cab);
+ acquire_cabinet_memory_free(cab);
}
/* if there were cabinets that were found but are not ok, point this out */
char *fname = NULL;
if (fi->attribs & cffile_A_NAME_IS_UTF) {
- fname = malloc(strlen(fi->filename) + 1);
+ fname = acquire_cabinet_memory_malloc(strlen(fi->filename) + 1);
if (fname) {
strcpy(fname, fi->filename);
convertUTF((UBYTE *) fname);
fname ? fname : fi->filename
);
- if (fname) free(fname);
+ if (fname) acquire_cabinet_memory_free(fname);
}
#endif /* CAPTIVE */
switch (ct2) {
case cffoldCOMPTYPE_LZX:
if (LZX(window)) {
- free(LZX(window));
+ acquire_cabinet_memory_free(LZX(window));
LZX(window) = NULL;
}
break;
case cffoldCOMPTYPE_QUANTUM:
if (QTM(window)) {
- free(QTM(window));
+ acquire_cabinet_memory_free(QTM(window));
QTM(window) = NULL;
}
break;
/* find if there's a directory path in the origcab */
tail = origcab ? strrchr(origcab, '/') : NULL;
- if ((cab = (char *) malloc((tail ? tail-origcab : 1) + strlen(name) + 2))) {
+ if ((cab = (char *) acquire_cabinet_memory_malloc((tail ? tail-origcab : 1) + strlen(name) + 2))) {
/* add the directory path from the original cabinet name */
if (tail) {
memcpy(cab, origcab, tail-origcab);
* otherwise, pretend nothing happened
*/
if (found) {
- free((void *) *cabname);
+ acquire_cabinet_memory_free((void *) *cabname);
*cabname = cab;
}
else {
- free((void *) cab);
+ acquire_cabinet_memory_free((void *) cab);
}
}
}