diff options
| author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-23 01:33:50 +0200 | 
|---|---|---|
| committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-23 02:09:51 +0200 | 
| commit | 7c028e224978e1d5a4f207cc42b9eb58d81897dd (patch) | |
| tree | d7165e3b9d1a7041cd79712526ad472c21135bdc /lib/comp | |
| parent | 0a5383ccdf8e87d2259d02a9ff44420b3bc3f58d (diff) | |
Some simple search/replace cases for allocation
This commit exchanges some malloc(x + y * z) patterns that can be found
with a simple git grep and are obvious for the new wrappers.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp')
| -rw-r--r-- | lib/comp/block_processor.c | 2 | ||||
| -rw-r--r-- | lib/comp/block_processor_parallel.c | 11 | ||||
| -rw-r--r-- | lib/comp/create_block.c | 2 | ||||
| -rw-r--r-- | lib/comp/internal.h | 1 | ||||
| -rw-r--r-- | lib/comp/lzo.c | 4 | 
5 files changed, 9 insertions, 11 deletions
| diff --git a/lib/comp/block_processor.c b/lib/comp/block_processor.c index 5938b3a..06dc384 100644 --- a/lib/comp/block_processor.c +++ b/lib/comp/block_processor.c @@ -29,7 +29,7 @@ block_processor_t *block_processor_create(size_t max_block_size,  					  void *user,  					  block_cb callback)  { -	block_processor_t *proc = calloc(1, sizeof(*proc) + max_block_size); +	block_processor_t *proc = alloc_flex(sizeof(*proc), 1, max_block_size);  	(void)num_workers;  	if (proc == NULL) { diff --git a/lib/comp/block_processor_parallel.c b/lib/comp/block_processor_parallel.c index 985c900..b58ad5c 100644 --- a/lib/comp/block_processor_parallel.c +++ b/lib/comp/block_processor_parallel.c @@ -119,15 +119,13 @@ block_processor_t *block_processor_create(size_t max_block_size,  {  	block_processor_t *proc;  	unsigned int i; -	size_t size;  	int ret;  	if (num_workers < 1)  		num_workers = 1; -	size = sizeof(proc->workers[0]) * num_workers; - -	proc = calloc(1, sizeof(*proc) + size); +	proc = alloc_flex(sizeof(*proc), +			  sizeof(proc->workers[0]), num_workers);  	if (proc == NULL) {  		perror("Creating block processor");  		return NULL; @@ -153,10 +151,9 @@ block_processor_t *block_processor_create(size_t max_block_size,  		goto fail_cond;  	} -	size = sizeof(compress_worker_t) + max_block_size; -  	for (i = 0; i < num_workers; ++i) { -		proc->workers[i] = calloc(1, size); +		proc->workers[i] = alloc_flex(sizeof(compress_worker_t), +					      1, max_block_size);  		if (proc->workers[i] == NULL) {  			perror("Creating block worker data"); diff --git a/lib/comp/create_block.c b/lib/comp/create_block.c index e410091..90344bb 100644 --- a/lib/comp/create_block.c +++ b/lib/comp/create_block.c @@ -16,7 +16,7 @@  block_t *create_block(const char *filename, int fd, size_t size,  		      void *user, uint32_t flags)  { -	block_t *blk = calloc(1, sizeof(*blk) + size); +	block_t *blk = alloc_flex(sizeof(*blk), 1, size);  	if (blk == NULL) {  		perror(filename); diff --git a/lib/comp/internal.h b/lib/comp/internal.h index 6bcd8fc..986266d 100644 --- a/lib/comp/internal.h +++ b/lib/comp/internal.h @@ -10,6 +10,7 @@  #include "config.h"  #include "compress.h" +#include "util.h"  int generic_write_options(int fd, const void *data, size_t size); diff --git a/lib/comp/lzo.c b/lib/comp/lzo.c index 66c2f59..09ef75c 100644 --- a/lib/comp/lzo.c +++ b/lib/comp/lzo.c @@ -182,7 +182,7 @@ static compressor_t *lzo_create_copy(compressor_t *cmp)  	lzo_compressor_t *other = (lzo_compressor_t *)cmp;  	lzo_compressor_t *lzo; -	lzo = calloc(1, sizeof(*lzo) + lzo_algs[other->algorithm].bufsize); +	lzo = alloc_flex(sizeof(*lzo), 1, lzo_algs[other->algorithm].bufsize);  	if (lzo == NULL) {  		perror("creating additional lzo compressor"); @@ -282,7 +282,7 @@ compressor_t *create_lzo_compressor(bool compress, size_t block_size,  	if (options != NULL && process_options(options, &alg, &level) != 0)  		return NULL; -	lzo = calloc(1, sizeof(*lzo) + lzo_algs[alg].bufsize); +	lzo = alloc_flex(sizeof(*lzo), 1, lzo_algs[alg].bufsize);  	base = (compressor_t *)lzo;  	if (lzo == NULL) { | 
