Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
#include <pakfire/digest.h>
#include <pakfire/pakfire.h>
+/*
+ This implementation of realloc frees the original buffer
+ if it could not be resized.
+*/
+static inline void* pakfire_realloc(void* p, size_t size) {
+ void* n = realloc(p, size);
+ if (!n) {
+ if (p)
+ free(p);
+ }
+
+ return n;
+}
+
int pakfire_path_exists(const char* path);
int pakfire_path_match(const char* p, const char* s);
time_t pakfire_path_age(const char* path);
ERR_error_string_n(ERR_get_error(), error, sizeof(error));
CTX_ERROR(ctx, "Could not read data: %s\n", error);
- r = 1;
+ r = -EINVAL;
goto ERROR;
// Break if no more data could be read
*length += bytes_read;
// Allocate an output buffer
- p = realloc(p, *length);
+ p = pakfire_realloc(p, *length);
if (!p) {
CTX_ERROR(ctx, "Could not allocate buffer: %m\n");
- r = 1;
+ r = -errno;
goto ERROR;
}