Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for memory allocation and freeing #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
:Contact: [email protected]
:URL: http://www.blosc.org

Changes from 1.0.0 to 1.1.0
===========================
- Use H5allocate_memory() and H5free_memory() rather than malloc() and free().
- Simplified blosc_plugin.c, removed blosc_plugin.h.

Changes from 0.0.1 to 1.0.0
===========================
Expand Down
33 changes: 15 additions & 18 deletions src/blosc_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ size_t blosc_filter(unsigned flags, size_t cd_nelmts,

herr_t blosc_set_local(hid_t dcpl, hid_t type, hid_t space);

H5Z_class_t BLOSC_FILTER[1] = {{
H5Z_CLASS_T_VERS,
(H5Z_filter_t)(FILTER_BLOSC),
1, 1,
"blosc",
NULL,
(H5Z_set_local_func_t)(blosc_set_local),
(H5Z_func_t)(blosc_filter)
}};


/* Register the filter, passing on the HDF5 return value */
int register_blosc(char **version, char **date){

int retval;

H5Z_class_t filter_class = {
H5Z_CLASS_T_VERS,
(H5Z_filter_t)(FILTER_BLOSC),
1, 1,
"blosc",
NULL,
(H5Z_set_local_func_t)(blosc_set_local),
(H5Z_func_t)(blosc_filter)
};

retval = H5Zregister(&filter_class);
retval = H5Zregister(BLOSC_FILTER);
if(retval<0){
PUSH_ERR("register_blosc", H5E_CANTREGISTER, "Can't register Blosc filter");
}
Expand Down Expand Up @@ -157,7 +157,6 @@ size_t blosc_filter(unsigned flags, size_t cd_nelmts,
int code;
char* compname = "blosclz"; /* The compressor by default */
char* complist;
char errmsg[256];

/* Filter params that are always set */
typesize = cd_values[2]; /* The datatype size */
Expand Down Expand Up @@ -207,7 +206,7 @@ size_t blosc_filter(unsigned flags, size_t cd_nelmts,
nbytes, outbuf_size);
#endif

outbuf = malloc(outbuf_size);
outbuf = H5allocate_memory(outbuf_size, 0);

if (outbuf == NULL) {
PUSH_ERR("blosc_filter", H5E_CALLBACK,
Expand All @@ -228,8 +227,6 @@ size_t blosc_filter(unsigned flags, size_t cd_nelmts,
/* declare dummy variables */
size_t cbytes, blocksize;

free(outbuf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just verifying that when we get here outbuf will always be NULL so free was a no-op?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it appears not to be needed.


/* Extract the exact outbuf_size from the buffer header.
*
* NOTE: the guess value got from "cd_values" corresponds to the
Expand All @@ -243,7 +240,7 @@ size_t blosc_filter(unsigned flags, size_t cd_nelmts,
fprintf(stderr, "Blosc: Decompress %zd chunk w/buffer %zd\n", nbytes, outbuf_size);
#endif

outbuf = malloc(outbuf_size);
outbuf = H5allocate_memory(outbuf_size, 0);

if (outbuf == NULL) {
PUSH_ERR("blosc_filter", H5E_CALLBACK, "Can't allocate decompression buffer");
Expand All @@ -259,14 +256,14 @@ size_t blosc_filter(unsigned flags, size_t cd_nelmts,
} /* compressing vs decompressing */

if (status != 0) {
free(*buf);
H5free_memory(*buf);
*buf = outbuf;
*buf_size = outbuf_size;
return status; /* Size of compressed/decompressed data */
}

failed:
free(outbuf);
H5free_memory(outbuf);
return 0;

} /* End filter function */
8 changes: 4 additions & 4 deletions src/blosc_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern "C" {
#endif

#include "blosc.h"
#include "hdf5.h"

/* Filter revision number, starting at 1 */
/* #define FILTER_BLOSC_VERSION 1 */
Expand All @@ -14,11 +15,10 @@ extern "C" {
/* Filter ID registered with the HDF Group */
#define FILTER_BLOSC 32001

H5_DLLVAR H5Z_class_t BLOSC_FILTER[1];

/* Registers the filter with the HDF5 library. */
#if defined(_MSC_VER)
__declspec(dllexport)
#endif /* defined(_MSC_VER) */
int register_blosc(char **version, char **date);
H5_DLL int register_blosc(char **version, char **date);

#ifdef __cplusplus
}
Expand Down
36 changes: 2 additions & 34 deletions src/blosc_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,8 @@
*
*/


#include <stdint.h>


#define H5Z_class_t_vers 2

#include "blosc_plugin.h"
#include "blosc_filter.h"


/* Prototypes for filter function in blosc_filter.c. */
size_t blosc_filter(unsigned flags, size_t cd_nelmts,
const unsigned cd_values[], size_t nbytes,
size_t* buf_size, void** buf);

herr_t blosc_set_local(hid_t dcpl, hid_t type, hid_t space);


H5Z_class_t blosc_H5Filter[1] = {
{
H5Z_CLASS_T_VERS,
(H5Z_filter_t)(FILTER_BLOSC),
1, /* encoder_present flag (set to true) */
1, /* decoder_present flag (set to true) */
"blosc",
/* Filter info */
NULL, /* The "can apply" callback */
(H5Z_set_local_func_t)(blosc_set_local), /* The "set local" callback */
(H5Z_func_t)(blosc_filter), /* The filter function */
}
};

#include "H5PLextern.h"

H5PL_type_t H5PLget_plugin_type(void) { return H5PL_TYPE_FILTER; }


const void* H5PLget_plugin_info(void) { return blosc_H5Filter; }
const void* H5PLget_plugin_info(void) { return BLOSC_FILTER; }
36 changes: 0 additions & 36 deletions src/blosc_plugin.h

This file was deleted.