if (!name2) return 0;
/* dup data */
data_size = size;
- if (compress == 1)
+ /* have bigger buffer for compress */
+ if (compress == 1)
data_size = 12 + ((size * 101) / 100);
data2 = malloc(data_size);
if (!data2)
if (compress == 1)
{
uLongf buflen;
-
+ int ok;
+
/* compress the data with max compression */
- if (compress2((Bytef *)data2, &buflen, (Bytef *)data,
- (uLong)size, 9) != Z_OK)
+ buflen = (uLongf)data_size;
+ if ((ok = compress2((Bytef *)data2, &buflen, (Bytef *)data,
+ (uLong)size, 9)) != Z_OK)
{
free(name2);
free(data2);
compress = 0;
data_size = size;
}
+ else
+ {
+ void *data3;
+
+ data3 = realloc(data2, data_size);
+ if (data3) data2 = data3;
+ }
}
if (!compress)
memcpy(data2, data, size);