#include <stdlib.h>
#include "packet.h"
+#include "xmalloc.h"
struct pa_packet* pa_packet_new(size_t length) {
struct pa_packet *p;
assert(length);
- p = malloc(sizeof(struct pa_packet)+length);
- assert(p);
-
+ p = pa_xmalloc(sizeof(struct pa_packet)+length);
p->ref = 1;
p->length = length;
p->data = (uint8_t*) (p+1);
struct pa_packet* pa_packet_new_dynamic(uint8_t* data, size_t length) {
struct pa_packet *p;
assert(data && length);
- p = malloc(sizeof(struct pa_packet));
- assert(p);
-
+ p = pa_xmalloc(sizeof(struct pa_packet));
p->ref = 1;
p->length = length;
p->data = data;
if (p->ref == 0) {
if (p->type == PA_PACKET_DYNAMIC)
- free(p->data);
- free(p);
+ pa_xfree(p->data);
+ pa_xfree(p);
}
}