mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-01-14 03:35:52 +00:00
Use spice allocator in server/
This commit is contained in:
parent
af4672326b
commit
d94cb8e1ba
@ -245,11 +245,7 @@ RedChannel *red_channel_create(int size, RedsStreamContext *peer, CoreInterface
|
||||
ASSERT(size >= sizeof(*channel));
|
||||
ASSERT(config_socket && disconnect && handle_message && alloc_recv_buf &&
|
||||
release_item);
|
||||
if (!(channel = malloc(size))) {
|
||||
red_printf("malloc failed");
|
||||
goto error1;
|
||||
}
|
||||
memset(channel, 0, size);
|
||||
channel = spice_malloc0(size);
|
||||
|
||||
channel->handle_acks = handle_acks;
|
||||
channel->disconnect = disconnect;
|
||||
@ -282,7 +278,7 @@ RedChannel *red_channel_create(int size, RedsStreamContext *peer, CoreInterface
|
||||
channel->outgoing.on_msg_done = red_channel_peer_on_out_msg_done;
|
||||
|
||||
if (!config_socket(channel)) {
|
||||
goto error2;
|
||||
goto error;
|
||||
}
|
||||
|
||||
channel->core->set_file_handlers(channel->core, channel->peer->socket,
|
||||
@ -290,9 +286,8 @@ RedChannel *red_channel_create(int size, RedsStreamContext *peer, CoreInterface
|
||||
|
||||
return channel;
|
||||
|
||||
error2:
|
||||
error:
|
||||
free(channel);
|
||||
error1:
|
||||
peer->cb_free(peer);
|
||||
|
||||
return NULL;
|
||||
@ -480,10 +475,7 @@ void red_channel_pipe_add_tail(RedChannel *channel, PipeItem *item)
|
||||
|
||||
void red_channel_pipe_add_type(RedChannel *channel, int pipe_item_type)
|
||||
{
|
||||
PipeItem *item = malloc(sizeof(*item));
|
||||
if (!item) {
|
||||
red_error("malloc failed");
|
||||
}
|
||||
PipeItem *item = spice_new(PipeItem, 1);
|
||||
red_channel_pipe_item_init(channel, item, pipe_item_type);
|
||||
red_channel_pipe_add(channel, item);
|
||||
|
||||
|
||||
@ -82,10 +82,7 @@ static int FUNC_NAME(add)(CHANNEL *channel, uint64_t id, size_t size)
|
||||
CacheItem *item;
|
||||
int key;
|
||||
|
||||
item = malloc(sizeof(*item));
|
||||
if (!item) {
|
||||
return FALSE;
|
||||
}
|
||||
item = spice_new(CacheItem, 1);
|
||||
|
||||
channel->VAR_NAME(available) -= size;
|
||||
while (channel->VAR_NAME(available) < 0) {
|
||||
|
||||
@ -68,10 +68,7 @@ static int FUNC_NAME(add)(CACHE *cache, uint64_t id, uint32_t size, CHANNEL *cha
|
||||
|
||||
ASSERT(size > 0);
|
||||
|
||||
item = malloc(sizeof(*item));
|
||||
if (!item) {
|
||||
return FALSE;
|
||||
}
|
||||
item = spice_new(NewCacheItem, 1);
|
||||
serial = channel_message_serial((RedChannel *)channel);
|
||||
|
||||
pthread_mutex_lock(&cache->lock);
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include "spice.h"
|
||||
#include "mem.h"
|
||||
#include <spice/protocol.h>
|
||||
#include <spice/macros.h>
|
||||
|
||||
|
||||
@ -483,10 +483,7 @@ RedDispatcher *red_dispatcher_init(QXLInterface *qxl_interface)
|
||||
red_error("socketpair failed %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (!(dispatcher = malloc(sizeof(RedDispatcher)))) {
|
||||
red_error("malloc failed");
|
||||
}
|
||||
memset(dispatcher, 0, sizeof(RedDispatcher));
|
||||
dispatcher = spice_new0(RedDispatcher, 1);
|
||||
dispatcher->channel = channels[0];
|
||||
init_data.qxl_interface = dispatcher->qxl_interface = qxl_interface;
|
||||
init_data.id = qxl_interface->base.id;
|
||||
@ -540,10 +537,8 @@ RedDispatcher *red_dispatcher_init(QXLInterface *qxl_interface)
|
||||
|
||||
read_message(dispatcher->channel, &message);
|
||||
ASSERT(message == RED_WORKER_MESSAGE_READY);
|
||||
if (!(reds_channel = malloc(sizeof(Channel)))) {
|
||||
red_error("reds channel malloc failed");
|
||||
}
|
||||
memset(reds_channel, 0, sizeof(Channel));
|
||||
|
||||
reds_channel = spice_new0(Channel, 1);
|
||||
reds_channel->type = SPICE_CHANNEL_DISPLAY;
|
||||
reds_channel->id = qxl_interface->base.id;
|
||||
reds_channel->link = red_dispatcher_set_peer;
|
||||
@ -552,10 +547,7 @@ RedDispatcher *red_dispatcher_init(QXLInterface *qxl_interface)
|
||||
reds_channel->data = dispatcher;
|
||||
reds_register_channel(reds_channel);
|
||||
|
||||
if (!(cursor_channel = malloc(sizeof(Channel)))) {
|
||||
red_error("reds channel malloc failed");
|
||||
}
|
||||
memset(cursor_channel, 0, sizeof(Channel));
|
||||
cursor_channel = spice_new0(Channel, 1);
|
||||
cursor_channel->type = SPICE_CHANNEL_CURSOR;
|
||||
cursor_channel->id = qxl_interface->base.id;
|
||||
cursor_channel->link = red_dispatcher_set_cursor_peer;
|
||||
|
||||
@ -645,10 +645,7 @@ static inline RedSocketRawSndBuf *__tunnel_worker_alloc_socket_snd_buf(TunnelWor
|
||||
ret = worker->free_snd_buf;
|
||||
worker->free_snd_buf = (RedSocketRawSndBuf *)worker->free_snd_buf->base.next;
|
||||
} else {
|
||||
ret = (RedSocketRawSndBuf *)malloc(sizeof(*ret));
|
||||
if (!ret) {
|
||||
red_error("malloc of send buf failed");
|
||||
}
|
||||
ret = spice_new(RedSocketRawSndBuf, 1);
|
||||
}
|
||||
ret->base.data = ret->buf;
|
||||
ret->base.size = 0;
|
||||
@ -707,10 +704,7 @@ static inline RedSocketRawRcvBuf *__tunnel_worker_alloc_socket_rcv_buf(TunnelWor
|
||||
ret = worker->free_rcv_buf;
|
||||
worker->free_rcv_buf = (RedSocketRawRcvBuf *)worker->free_rcv_buf->base.next;
|
||||
} else {
|
||||
ret = (RedSocketRawRcvBuf *)malloc(sizeof(*ret));
|
||||
if (!ret) {
|
||||
red_error("malloc of send buf failed");
|
||||
}
|
||||
ret = spice_new(RedSocketRawRcvBuf, 1);
|
||||
}
|
||||
ret->msg_info = (SpiceMsgcTunnelSocketData *)ret->buf;
|
||||
ret->base.usr_opaque = NULL;
|
||||
@ -853,7 +847,7 @@ static void __ready_queue_push(ReadyTunneledChunkQueue *queue, ReadyTunneledChun
|
||||
static void ready_queue_add_orig_chunk(ReadyTunneledChunkQueue *queue, RawTunneledBuffer *origin,
|
||||
uint8_t *data, int size)
|
||||
{
|
||||
ReadyTunneledChunk *chunk = malloc(sizeof(ReadyTunneledChunk));
|
||||
ReadyTunneledChunk *chunk = spice_new(ReadyTunneledChunk, 1);
|
||||
chunk->type = READY_TUNNELED_CHUNK_TYPE_ORIG;
|
||||
chunk->origin = tunneled_buffer_ref(origin);
|
||||
chunk->data = data;
|
||||
@ -921,8 +915,7 @@ static inline TunneledBufferProcessQueue *__tunnel_socket_alloc_simple_process_q
|
||||
uint32_t service_type,
|
||||
uint32_t direction_type)
|
||||
{
|
||||
TunneledBufferProcessQueue *ret_queue = malloc(sizeof(TunneledBufferProcessQueue));
|
||||
memset(ret_queue, 0, sizeof(TunneledBufferProcessQueue));
|
||||
TunneledBufferProcessQueue *ret_queue = spice_new0(TunneledBufferProcessQueue, 1);
|
||||
ret_queue->service_type = service_type;
|
||||
ret_queue->direction = direction_type;
|
||||
ret_queue->usr_opaque = sckt;
|
||||
@ -979,12 +972,7 @@ static void tunnel_send_packet(void *opaque_tunnel, const uint8_t *pkt, int pkt_
|
||||
|
||||
void *red_tunnel_attach(CoreInterface *core_interface, NetWireInterface *vlan_interface)
|
||||
{
|
||||
TunnelWorker *worker = (TunnelWorker *)malloc(sizeof(TunnelWorker));
|
||||
|
||||
if (!worker) {
|
||||
red_error("malloc of tunnel worker failed");
|
||||
}
|
||||
memset(worker, 0, sizeof(*worker));
|
||||
TunnelWorker *worker = spice_new0(TunnelWorker, 1);
|
||||
|
||||
worker->core_interface = core_interface;
|
||||
worker->vlan_interface = vlan_interface;
|
||||
@ -1056,12 +1044,7 @@ static inline TunnelService *__tunnel_worker_add_service(TunnelWorker *worker, u
|
||||
char *name, char *description,
|
||||
struct in_addr *virt_ip)
|
||||
{
|
||||
TunnelService *new_service = malloc(size);
|
||||
|
||||
if (!new_service) {
|
||||
red_error("malloc of TunnelService failed");
|
||||
}
|
||||
memset(new_service, 0, size);
|
||||
TunnelService *new_service = spice_malloc0(size);
|
||||
|
||||
if (!virt_ip) {
|
||||
TunnelService *service_of_same_group;
|
||||
@ -1290,7 +1273,7 @@ static RedSocket *tunnel_worker_create_socket(TunnelWorker *worker, uint16_t loc
|
||||
new_socket = __tunnel_worker_find_free_socket(worker);
|
||||
|
||||
if (!new_socket) {
|
||||
red_error("malloc of RedSocket failed");
|
||||
red_error("creation of RedSocket failed");
|
||||
}
|
||||
|
||||
tunnel_worker_alloc_socket(worker, new_socket, local_port, far_service, slirp_s);
|
||||
@ -1662,11 +1645,7 @@ static uint8_t *tunnel_channel_alloc_msg_rcv_buf(RedChannel *channel, SpiceDataH
|
||||
return (__tunnel_worker_alloc_socket_rcv_buf(tunnel_channel->worker)->buf);
|
||||
} else if ((msg_header->type == SPICE_MSGC_MIGRATE_DATA) ||
|
||||
(msg_header->type == SPICE_MSGC_TUNNEL_SERVICE_ADD)) {
|
||||
uint8_t *ret = malloc(msg_header->size);
|
||||
if (!ret) {
|
||||
red_error("failed allocating");
|
||||
}
|
||||
return ret;
|
||||
return spice_malloc(msg_header->size);
|
||||
} else {
|
||||
return (tunnel_channel->control_rcv_buf);
|
||||
}
|
||||
@ -1771,13 +1750,7 @@ static int tunnel_channel_handle_migrate_mark(TunnelChannel *channel)
|
||||
return FALSE;
|
||||
}
|
||||
channel->expect_migrate_mark = FALSE;
|
||||
migrate_item = (TunnelMigrateItem *)malloc(sizeof(*migrate_item));
|
||||
|
||||
if (!migrate_item) {
|
||||
red_error("failed alloc TunnelMigrateItem");
|
||||
}
|
||||
|
||||
memset(migrate_item, 0, sizeof(*migrate_item));
|
||||
migrate_item = spice_new0(TunnelMigrateItem, 1);
|
||||
migrate_item->base.type = PIPE_ITEM_TYPE_MIGRATE_DATA;
|
||||
|
||||
migrate_item->slirp_state_size = net_slirp_state_export(&migrate_item->slirp_state);
|
||||
@ -1789,19 +1762,12 @@ static int tunnel_channel_handle_migrate_mark(TunnelChannel *channel)
|
||||
migrate_item->services_list_size = sizeof(TunnelMigrateServicesList) +
|
||||
(sizeof(uint32_t)*channel->worker->num_services);
|
||||
migrate_item->services_list =
|
||||
(TunnelMigrateServicesList *)malloc(migrate_item->services_list_size);
|
||||
if (!migrate_item->services_list) {
|
||||
red_error("failed alloc services list");
|
||||
}
|
||||
(TunnelMigrateServicesList *)spice_malloc(migrate_item->services_list_size);
|
||||
migrate_item->services_list->num_services = channel->worker->num_services;
|
||||
|
||||
migrate_item->services = (TunnelMigrateServiceItem *)malloc(
|
||||
migrate_item->services = (TunnelMigrateServiceItem *)spice_malloc(
|
||||
channel->worker->num_services * sizeof(TunnelMigrateServiceItem));
|
||||
|
||||
if (!migrate_item->services) {
|
||||
red_error("failed alloc services items");
|
||||
}
|
||||
|
||||
for (mig_service = migrate_item->services,
|
||||
service = (TunnelService *)ring_get_head(&channel->worker->services);
|
||||
service;
|
||||
@ -1815,11 +1781,8 @@ static int tunnel_channel_handle_migrate_mark(TunnelChannel *channel)
|
||||
|
||||
migrate_item->sockets_list_size = sizeof(TunnelMigrateSocketList) +
|
||||
(sizeof(uint32_t)*channel->worker->num_sockets);
|
||||
migrate_item->sockets_list = (TunnelMigrateSocketList *)malloc(
|
||||
migrate_item->sockets_list_size);
|
||||
if (!migrate_item->sockets_list) {
|
||||
red_error("failed alloc sockets list");
|
||||
}
|
||||
migrate_item->sockets_list =
|
||||
(TunnelMigrateSocketList *) spice_malloc(migrate_item->sockets_list_size);
|
||||
|
||||
migrate_item->sockets_list->num_sockets = channel->worker->num_sockets;
|
||||
|
||||
@ -1918,11 +1881,7 @@ static void restore_tokens_buf_release(RawTunneledBuffer *buf)
|
||||
|
||||
RawTunneledBuffer *__tunnel_socket_alloc_restore_tokens_buf(RedSocket *sckt, int num_tokens)
|
||||
{
|
||||
RedSocketRestoreTokensBuf *buf = (RedSocketRestoreTokensBuf *)malloc(sizeof(*buf));
|
||||
if (!buf) {
|
||||
red_error("failed alloc");
|
||||
}
|
||||
memset(buf, 0, sizeof(*buf));
|
||||
RedSocketRestoreTokensBuf *buf = spice_new0(RedSocketRestoreTokensBuf, 1);
|
||||
|
||||
buf->base.base.usr_opaque = sckt;
|
||||
buf->base.base.refs = 1;
|
||||
|
||||
@ -1315,10 +1315,7 @@ static inline void red_pipe_add_tail(RedChannel *channel, PipeItem *item)
|
||||
|
||||
static void red_pipe_add_verb(RedChannel* channel, uint16_t verb)
|
||||
{
|
||||
VerbItem *item = malloc(sizeof(*item));
|
||||
if (!item) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
VerbItem *item = spice_new(VerbItem, 1);
|
||||
red_pipe_item_init(&item->base, PIPE_ITEM_TYPE_VERB);
|
||||
item->verb = verb;
|
||||
red_pipe_add(channel, &item->base);
|
||||
@ -1326,10 +1323,7 @@ static void red_pipe_add_verb(RedChannel* channel, uint16_t verb)
|
||||
|
||||
static void red_pipe_add_type(RedChannel* channel, int pipe_item_type)
|
||||
{
|
||||
PipeItem *item = malloc(sizeof(*item));
|
||||
if (!item) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
PipeItem *item = spice_new(PipeItem, 1);
|
||||
red_pipe_item_init(item, pipe_item_type);
|
||||
red_pipe_add(channel, item);
|
||||
}
|
||||
@ -2048,10 +2042,7 @@ static void exclude_region(RedWorker *worker, Ring *ring, RingItem *ring_item, Q
|
||||
|
||||
static inline Container *__new_container(RedWorker *worker, DrawItem *item)
|
||||
{
|
||||
Container *container = malloc(sizeof(Container));
|
||||
if (!container) {
|
||||
return NULL;
|
||||
}
|
||||
Container *container = spice_new(Container, 1);
|
||||
worker->containers_count++;
|
||||
#ifdef PIPE_DEBUG
|
||||
container->base.id = ++worker->last_id;
|
||||
@ -2240,10 +2231,7 @@ static inline void red_detach_stream(RedWorker *worker, Stream *stream)
|
||||
|
||||
static StreamClipItem *__new_stream_clip(DisplayChannel* channel, StreamAgent *agent)
|
||||
{
|
||||
StreamClipItem *item = (StreamClipItem *)malloc(sizeof(*item));
|
||||
if (!item) {
|
||||
PANIC("alloc failed");
|
||||
}
|
||||
StreamClipItem *item = spice_new(StreamClipItem, 1);
|
||||
red_pipe_item_init((PipeItem *)item, PIPE_ITEM_TYPE_STREAM_CLIP);
|
||||
|
||||
item->stream_agent = agent;
|
||||
@ -2351,9 +2339,7 @@ static inline void red_detach_stream_gracefully(RedWorker *worker, Stream *strea
|
||||
if ((channel = worker->display_channel) && !pipe_item_is_linked(&stream->current->pipe_item)) {
|
||||
UpgradeItem *upgrade_item;
|
||||
|
||||
if (!(upgrade_item = (UpgradeItem *)malloc(sizeof(*upgrade_item)))) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
upgrade_item = spice_new(UpgradeItem, 1);
|
||||
upgrade_item->refs = 1;
|
||||
red_pipe_item_init(&upgrade_item->base, PIPE_ITEM_TYPE_UPGRADE);
|
||||
upgrade_item->drawable = stream->current;
|
||||
@ -2370,16 +2356,14 @@ static inline void red_stop_stream_gracefully(RedWorker *worker, Stream *stream)
|
||||
{
|
||||
ASSERT(stream->current);
|
||||
if (worker->display_channel && !pipe_item_is_linked(&stream->current->pipe_item)) {
|
||||
UpgradeItem *item;
|
||||
if ((item = (UpgradeItem *)malloc(sizeof(*item)))) {
|
||||
item->refs = 1;
|
||||
red_pipe_item_init(&item->base, PIPE_ITEM_TYPE_UPGRADE);
|
||||
item->drawable = stream->current;
|
||||
item->drawable->refs++;
|
||||
item->rects = region_dup_rects(&item->drawable->tree_item.base.rgn,
|
||||
&item->n_rects);
|
||||
red_pipe_add((RedChannel *)worker->display_channel, &item->base);
|
||||
}
|
||||
UpgradeItem *item = spice_new(UpgradeItem, 1);
|
||||
item->refs = 1;
|
||||
red_pipe_item_init(&item->base, PIPE_ITEM_TYPE_UPGRADE);
|
||||
item->drawable = stream->current;
|
||||
item->drawable->refs++;
|
||||
item->rects = region_dup_rects(&item->drawable->tree_item.base.rgn,
|
||||
&item->n_rects);
|
||||
red_pipe_add((RedChannel *)worker->display_channel, &item->base);
|
||||
}
|
||||
red_stop_stream(worker, stream);
|
||||
}
|
||||
@ -2643,9 +2627,7 @@ static void red_create_stream(RedWorker *worker, Drawable *drawable)
|
||||
goto error_3;
|
||||
}
|
||||
|
||||
if (!(frame_buf = malloc(pict_size))) {
|
||||
goto error_3;
|
||||
}
|
||||
frame_buf = spice_malloc(pict_size);
|
||||
|
||||
if (avpicture_fill((AVPicture *)frame, frame_buf, av_ctx->pix_fmt, stream_width,
|
||||
stream_height) < 0) {
|
||||
@ -3390,10 +3372,7 @@ static inline Shadow *__new_shadow(RedWorker *worker, Drawable *item, SpicePoint
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Shadow *shadow = malloc(sizeof(Shadow));
|
||||
if (!shadow) {
|
||||
return NULL;
|
||||
}
|
||||
Shadow *shadow = spice_new(Shadow, 1);
|
||||
worker->shadows_count++;
|
||||
#ifdef PIPE_DEBUG
|
||||
shadow->base.id = ++worker->last_id;
|
||||
@ -3560,10 +3539,7 @@ static inline int red_handle_self_bitmap(RedWorker *worker, Drawable *drawable)
|
||||
height = drawable->qxl_drawable->bbox.bottom - drawable->qxl_drawable->bbox.top;
|
||||
dest_stride = width * sizeof(uint32_t);
|
||||
|
||||
if (!(image = malloc(sizeof(QXLImage) + height * dest_stride))) {
|
||||
red_printf("alloc failed");
|
||||
return FALSE;
|
||||
}
|
||||
image = spice_malloc_n_m(height, dest_stride, sizeof(QXLImage));
|
||||
dest = (uint8_t *)(image + 1);
|
||||
|
||||
image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
|
||||
@ -3700,8 +3676,7 @@ static void localize_path(RedWorker *worker, QXLPHYSICAL *in_path, uint32_t grou
|
||||
|
||||
ASSERT(in_path && *in_path);
|
||||
path = (QXLPath *)get_virt(worker, *in_path, sizeof(QXLPath), group_id);
|
||||
data = malloc(sizeof(uint32_t) + path->data_size);
|
||||
ASSERT(data);
|
||||
data = spice_malloc_n_m(1, path->data_size, sizeof(uint32_t));
|
||||
*in_path = (QXLPHYSICAL)data;
|
||||
*(uint32_t *)data = path->data_size;
|
||||
data += sizeof(uint32_t);
|
||||
@ -3733,8 +3708,7 @@ static void localize_str(RedWorker *worker, QXLPHYSICAL *in_str, uint32_t group_
|
||||
int memslot_id = get_memslot_id(worker, *in_str);
|
||||
|
||||
ASSERT(in_str);
|
||||
str = malloc(sizeof(uint32_t) + qxl_str->data_size);
|
||||
ASSERT(str);
|
||||
str = spice_malloc_n_m(1, qxl_str->data_size, sizeof(uint32_t));
|
||||
*in_str = (QXLPHYSICAL)str;
|
||||
str->length = qxl_str->length;
|
||||
str->flags = qxl_str->flags;
|
||||
@ -3777,8 +3751,7 @@ static void localize_clip(RedWorker *worker, SpiceClip *clip, uint32_t group_id)
|
||||
clip_rects = (QXLClipRects *)get_virt(worker, clip->data, sizeof(QXLClipRects), group_id);
|
||||
chunk = &clip_rects->chunk;
|
||||
ASSERT(clip->data);
|
||||
data = malloc(sizeof(uint32_t) + clip_rects->num_rects * sizeof(SpiceRect));
|
||||
ASSERT(data);
|
||||
data = spice_malloc_n_m(clip_rects->num_rects, sizeof(SpiceRect), sizeof(uint32_t));
|
||||
clip->data = (QXLPHYSICAL)data;
|
||||
*(uint32_t *)(data) = clip_rects->num_rects;
|
||||
data += sizeof(uint32_t);
|
||||
@ -3887,9 +3860,7 @@ static void image_cache_put(SpiceImageCache *spice_cache, uint64_t id, pixman_im
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(item = (ImageCacheItem *)malloc(sizeof(ImageCacheItem)))) {
|
||||
red_error("alloc failed");
|
||||
}
|
||||
item = spice_new(ImageCacheItem, 1);
|
||||
item->id = id;
|
||||
#ifdef IMAGE_CACHE_AGE
|
||||
item->age = cache->age;
|
||||
@ -3999,8 +3970,7 @@ static void localize_bitmap(RedWorker *worker, QXLPHYSICAL *in_bitmap, uint32_t
|
||||
} else {
|
||||
QXLPHYSICAL src_data;
|
||||
int size = image->bitmap.y * image->bitmap.stride;
|
||||
uint8_t *data = malloc(size);
|
||||
ASSERT(data);
|
||||
uint8_t *data = spice_malloc_n(image->bitmap.y, image->bitmap.stride);
|
||||
local_image->bitmap.data = (QXLPHYSICAL)data;
|
||||
src_data = image->bitmap.data;
|
||||
|
||||
@ -4038,11 +4008,7 @@ static void localize_bitmap(RedWorker *worker, QXLPHYSICAL *in_bitmap, uint32_t
|
||||
validate_virt(worker, (unsigned long)ents, slot_id, (num_ents * sizeof(uint32_t)),
|
||||
group_id);
|
||||
|
||||
shadow_palette = (SpicePalette *)malloc(sizeof(SpicePalette) + num_ents * sizeof(uint32_t) +
|
||||
sizeof(QXLPHYSICAL));
|
||||
if (!shadow_palette) {
|
||||
PANIC("SpicePalette malloc failed");
|
||||
}
|
||||
shadow_palette = (SpicePalette *)spice_malloc_n_m(num_ents, sizeof(uint32_t),sizeof(SpicePalette) + sizeof(QXLPHYSICAL));
|
||||
|
||||
memcpy(shadow_palette->ents, ents, num_ents * sizeof(uint32_t));
|
||||
shadow_palette->num_ents = num_ents;
|
||||
@ -4119,8 +4085,7 @@ static void localize_attr(RedWorker *worker, SpiceLineAttr *attr, uint32_t group
|
||||
ASSERT(attr->style);
|
||||
buf = (uint8_t *)get_virt(worker, attr->style, attr->style_nseg * sizeof(uint32_t),
|
||||
group_id);
|
||||
data = malloc(attr->style_nseg * sizeof(uint32_t));
|
||||
ASSERT(data);
|
||||
data = spice_malloc_n(attr->style_nseg, sizeof(uint32_t));
|
||||
memcpy(data, buf, attr->style_nseg * sizeof(uint32_t));
|
||||
attr->style = (QXLPHYSICAL)data;
|
||||
}
|
||||
@ -4689,11 +4654,7 @@ static void red_add_screen_image(RedWorker *worker)
|
||||
}
|
||||
|
||||
stride = worker->surface.context.width << 2;
|
||||
if (!(item = (ImageItem *)malloc(sizeof(ImageItem) +
|
||||
worker->surface.context.height * stride))) {
|
||||
//warn
|
||||
return;
|
||||
}
|
||||
item = (ImageItem *)spice_malloc_n_m(worker->surface.context.height, stride, sizeof(ImageItem));
|
||||
|
||||
red_pipe_item_init(&item->link, PIPE_ITEM_TYPE_IMAGE);
|
||||
|
||||
@ -4830,9 +4791,7 @@ static inline RedCompressBuf *red_display_alloc_compress_buf(DisplayChannel *dis
|
||||
ret = display_channel->send_data.free_compress_bufs;
|
||||
display_channel->send_data.free_compress_bufs = ret->next;
|
||||
} else {
|
||||
if (!(ret = malloc(sizeof(*ret)))) {
|
||||
return NULL;
|
||||
}
|
||||
ret = spice_new(RedCompressBuf, 1);
|
||||
}
|
||||
|
||||
ret->next = display_channel->send_data.used_compress_bufs;
|
||||
@ -4886,9 +4845,7 @@ static RedGlzDrawable *red_display_get_glz_drawable(DisplayChannel *channel, Dra
|
||||
return drawable->red_glz_drawable;
|
||||
}
|
||||
|
||||
if (!(ret = malloc(sizeof(*ret)))) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
ret = spice_new(RedGlzDrawable, 1);
|
||||
|
||||
ret->display_channel = channel;
|
||||
ret->qxl_drawable = drawable->qxl_drawable;
|
||||
@ -5141,17 +5098,17 @@ static void glz_usr_warn(GlzEncoderUsrContext *usr, const char *fmt, ...)
|
||||
|
||||
static void *quic_usr_malloc(QuicUsrContext *usr, int size)
|
||||
{
|
||||
return malloc(size);
|
||||
return spice_malloc(size);
|
||||
}
|
||||
|
||||
static void *lz_usr_malloc(LzUsrContext *usr, int size)
|
||||
{
|
||||
return malloc(size);
|
||||
return spice_malloc(size);
|
||||
}
|
||||
|
||||
static void *glz_usr_malloc(GlzEncoderUsrContext *usr, int size)
|
||||
{
|
||||
return malloc(size);
|
||||
return spice_malloc(size);
|
||||
}
|
||||
|
||||
static void quic_usr_free(QuicUsrContext *usr, void *ptr)
|
||||
@ -6444,10 +6401,7 @@ static void display_channel_push_release(DisplayChannel *channel, uint8_t type,
|
||||
|
||||
if (free_list->res->count == free_list->res_size) {
|
||||
SpiceResorceList *new_list;
|
||||
new_list = malloc(sizeof(*new_list) + free_list->res_size * sizeof(SpiceResorceID) * 2);
|
||||
if (!new_list) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
new_list = spice_malloc(sizeof(*new_list) + free_list->res_size * sizeof(SpiceResorceID) * 2);
|
||||
new_list->count = free_list->res->count;
|
||||
memcpy(new_list->resorces, free_list->res->resorces,
|
||||
new_list->count * sizeof(SpiceResorceID));
|
||||
@ -6652,9 +6606,7 @@ static inline int red_send_stream_data(DisplayChannel *display_channel, Drawable
|
||||
if (display_channel->send_data.stream_outbuf_size < min_buf_size) {
|
||||
uint8_t *new_buf;
|
||||
|
||||
if (!(new_buf = malloc(min_buf_size + FF_INPUT_BUFFER_PADDING_SIZE))) {
|
||||
return FALSE;
|
||||
}
|
||||
new_buf = spice_malloc(min_buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
|
||||
red_display_unshare_stream_buf(display_channel);
|
||||
free(display_channel->send_data.stream_outbuf);
|
||||
@ -6694,9 +6646,7 @@ static inline int red_send_stream_data(DisplayChannel *display_channel, Drawable
|
||||
new_size = display_channel->send_data.stream_outbuf_size * 2;
|
||||
new_size = MIN(new_size, max_size);
|
||||
|
||||
if (!(new_buf = malloc(new_size + FF_INPUT_BUFFER_PADDING_SIZE))) {
|
||||
return FALSE;
|
||||
}
|
||||
new_buf = spice_malloc(new_size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||
red_printf("new streaming video buf size %u", new_size);
|
||||
red_display_unshare_stream_buf(display_channel);
|
||||
free(display_channel->send_data.stream_outbuf);
|
||||
@ -7725,12 +7675,7 @@ static GlzSharedDictionary *_red_create_glz_dictionary(DisplayChannel *display,
|
||||
uint8_t id,
|
||||
GlzEncDictContext *opaque_dict)
|
||||
{
|
||||
GlzSharedDictionary *shared_dict = malloc(sizeof(*shared_dict));
|
||||
memset(shared_dict, 0, sizeof(*shared_dict)); // nullify the ring base
|
||||
|
||||
if (!shared_dict) {
|
||||
return NULL;
|
||||
}
|
||||
GlzSharedDictionary *shared_dict = spice_new0(GlzSharedDictionary, 1);
|
||||
shared_dict->dict = opaque_dict;
|
||||
shared_dict->id = id;
|
||||
shared_dict->refs = 1;
|
||||
@ -7845,11 +7790,7 @@ static void red_release_glz(DisplayChannel *channel)
|
||||
|
||||
static PixmapCache *red_create_pixmap_cache(uint8_t id, int64_t size)
|
||||
{
|
||||
PixmapCache *cache = malloc(sizeof(*cache));
|
||||
if (!cache) {
|
||||
return NULL;
|
||||
}
|
||||
memset(cache, 0, sizeof(*cache));
|
||||
PixmapCache *cache = spice_new0(PixmapCache, 1);
|
||||
ring_item_init(&cache->base);
|
||||
pthread_mutex_init(&cache->lock, NULL);
|
||||
cache->id = id;
|
||||
@ -8105,11 +8046,7 @@ static RedChannel *__new_channel(RedWorker *worker, int size, RedsStreamContext
|
||||
}
|
||||
|
||||
ASSERT(size >= sizeof(*channel));
|
||||
if (!(channel = malloc(size))) {
|
||||
red_printf("malloc failed");
|
||||
goto error1;
|
||||
}
|
||||
memset(channel, 0, size);
|
||||
channel = spice_malloc0(size);
|
||||
channel->id = worker->id;
|
||||
channel->listener.refs = 1;
|
||||
channel->listener.action = handler;
|
||||
@ -8235,20 +8172,16 @@ static void handle_new_display_channel(RedWorker *worker, RedsStreamContext *pee
|
||||
red_display_init_streams(display_channel);
|
||||
|
||||
stream_buf_size = FF_MIN_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE;
|
||||
if (!(display_channel->send_data.stream_outbuf = malloc(stream_buf_size))) {
|
||||
PANIC("alloc failed");
|
||||
}
|
||||
display_channel->send_data.stream_outbuf = spice_malloc(stream_buf_size);
|
||||
display_channel->send_data.stream_outbuf_size = FF_MIN_BUFFER_SIZE;
|
||||
red_display_share_stream_buf(display_channel);
|
||||
red_display_init_glz_data(display_channel);
|
||||
worker->display_channel = display_channel;
|
||||
|
||||
|
||||
if (!(display_channel->send_data.free_list.res = malloc(sizeof(SpiceResorceList) +
|
||||
DISPLAY_FREE_LIST_DEFAULT_SIZE *
|
||||
sizeof(SpiceResorceID)))) {
|
||||
PANIC("free list alloc failed");
|
||||
}
|
||||
display_channel->send_data.free_list.res =
|
||||
spice_malloc(sizeof(SpiceResorceList) +
|
||||
DISPLAY_FREE_LIST_DEFAULT_SIZE * sizeof(SpiceResorceID));
|
||||
display_channel->send_data.free_list.res_size = DISPLAY_FREE_LIST_DEFAULT_SIZE;
|
||||
red_ref_channel((RedChannel*)display_channel);
|
||||
on_new_display_channel(worker);
|
||||
@ -8348,8 +8281,7 @@ static void red_save_cursor(RedWorker *worker)
|
||||
|
||||
local = (LocalCursor *)worker->cursor;
|
||||
size = sizeof(CursorData) + sizeof(SpiceCursor) + local->data_size;
|
||||
cursor_data = malloc(size);
|
||||
ASSERT(cursor_data);
|
||||
cursor_data = spice_malloc(size);
|
||||
|
||||
cursor_data->position = worker->cursor_position;
|
||||
cursor_data->visible = worker->cursor_visible;
|
||||
@ -8365,10 +8297,7 @@ static LocalCursor *_new_local_cursor(SpiceCursorHeader *header, int data_size,
|
||||
{
|
||||
LocalCursor *local;
|
||||
|
||||
local = (LocalCursor *)malloc(sizeof(LocalCursor) + data_size);
|
||||
if (!local) {
|
||||
return NULL;
|
||||
}
|
||||
local = (LocalCursor *)spice_malloc(sizeof(LocalCursor) + data_size);
|
||||
|
||||
red_pipe_item_init(&local->base.pipe_data, PIPE_ITEM_TYPE_LOCAL_CURSOR);
|
||||
local->base.refs = 1;
|
||||
@ -8674,13 +8603,10 @@ static void inline red_create_mem_slots(RedWorker *worker)
|
||||
|
||||
ASSERT(worker->num_memslots > 0);
|
||||
ASSERT(worker->num_memslots_groups > 0);
|
||||
worker->mem_slots = (MemSlot **)malloc(sizeof(MemSlot *) * worker->num_memslots_groups);
|
||||
PANIC_ON(!worker->mem_slots);
|
||||
worker->mem_slots = spice_new(MemSlot *, worker->num_memslots_groups);
|
||||
|
||||
for (i = 0; i < worker->num_memslots_groups; ++i) {
|
||||
worker->mem_slots[i] = malloc(sizeof(MemSlot) * worker->num_memslots);
|
||||
PANIC_ON(!worker->mem_slots[i]);
|
||||
memset(worker->mem_slots[i], 0, sizeof(MemSlot) * worker->num_memslots);
|
||||
worker->mem_slots[i] = spice_new0(MemSlot, worker->num_memslots);
|
||||
}
|
||||
|
||||
worker->memslot_id_shift = 64 - worker->mem_slot_bits;
|
||||
|
||||
133
server/reds.c
133
server/reds.c
@ -536,11 +536,9 @@ static char *base64decode(const char *input, int length)
|
||||
BIO *b64;
|
||||
BIO *bmem;
|
||||
int n;
|
||||
char *buffer = (char *)malloc(length);
|
||||
memset(buffer, 0, length);
|
||||
char *buffer = (char *)spice_malloc0(length);
|
||||
char *inbuffer = (char *)spice_malloc0(length + 1);
|
||||
|
||||
char *inbuffer = (char *)malloc(length + 1);
|
||||
memset(inbuffer, 0, length + 1);
|
||||
memcpy(inbuffer, input, length);
|
||||
inbuffer[length] = '\n';
|
||||
|
||||
@ -1063,9 +1061,7 @@ static SimpleOutItem *new_simple_out_item(uint32_t type, int message_size)
|
||||
{
|
||||
SimpleOutItem *item;
|
||||
|
||||
if (!(item = (SimpleOutItem *)malloc(sizeof(*item) + message_size))) {
|
||||
return NULL;
|
||||
}
|
||||
item = (SimpleOutItem *)spice_malloc(sizeof(*item) + message_size);
|
||||
ring_item_init(&item->base.link);
|
||||
item->base.prepare = reds_prepare_basic_out_item;
|
||||
item->base.release = reds_free_basic_out_item;
|
||||
@ -1142,9 +1138,10 @@ static int send_ping(int size)
|
||||
struct timespec time_space;
|
||||
PingItem *item;
|
||||
|
||||
if (!reds->peer || !(item = (PingItem *)malloc(sizeof(*item)))) {
|
||||
if (!reds->peer) {
|
||||
return FALSE;
|
||||
}
|
||||
item = spice_new(PingItem, 1);
|
||||
ring_item_init(&item->base.link);
|
||||
item->base.prepare = reds_prepare_ping_item;
|
||||
item->base.release = reds_free_ping_item;
|
||||
@ -1640,10 +1637,7 @@ static void main_channel_push_migrate_data_item()
|
||||
{
|
||||
SendMainMigrateItem *item;
|
||||
|
||||
if (!(item = (SendMainMigrateItem *)malloc(sizeof(*item)))) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
memset(item, 0, sizeof(*item));
|
||||
item = spice_new0(SendMainMigrateItem, 1);
|
||||
ring_item_init(&item->base.link);
|
||||
item->base.prepare = main_channel_send_migrate_data_item;
|
||||
item->base.release = main_channelrelease_migrate_data_item;
|
||||
@ -1770,11 +1764,7 @@ static int main_channel_restore_vdi_wqueue(MainMigrateData *data, uint8_t *pos,
|
||||
reds_disconnect();
|
||||
return FALSE;
|
||||
}
|
||||
if (!(buf = malloc(sizeof(VDInternalBuf)))) {
|
||||
red_printf("no internal buff");
|
||||
reds_disconnect();
|
||||
return FALSE;
|
||||
}
|
||||
buf = spice_new(VDInternalBuf, 1);
|
||||
ring_item_init(&buf->base.link);
|
||||
buf->base.free = free_tmp_internal_buf;
|
||||
buf->base.now = (uint8_t *)&buf->base.chunk_header;
|
||||
@ -2568,11 +2558,7 @@ static void inputs_link(Channel *channel, RedsStreamContext *peer, int migration
|
||||
red_printf("");
|
||||
ASSERT(channel->data == NULL);
|
||||
|
||||
if (!(inputs_state = malloc(sizeof(InputsState)))) {
|
||||
red_printf("alloc input state failed");
|
||||
close(peer->socket);
|
||||
return;
|
||||
}
|
||||
inputs_state = spice_new0(InputsState, 1);
|
||||
|
||||
delay_val = 1;
|
||||
if (setsockopt(peer->socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) {
|
||||
@ -2584,7 +2570,6 @@ static void inputs_link(Channel *channel, RedsStreamContext *peer, int migration
|
||||
red_printf("fcntl failed, %s", strerror(errno));
|
||||
}
|
||||
|
||||
memset(inputs_state, 0, sizeof(*inputs_state));
|
||||
inputs_state->peer = peer;
|
||||
inputs_state->end_pos = 0;
|
||||
inputs_state->channel = channel;
|
||||
@ -2661,10 +2646,8 @@ static void openssl_init(RedLinkInfo *link)
|
||||
static void inputs_init()
|
||||
{
|
||||
Channel *channel;
|
||||
if (!(channel = malloc(sizeof(Channel)))) {
|
||||
red_error("alloc inputs chanel failed");
|
||||
}
|
||||
memset(channel, 0, sizeof(Channel));
|
||||
|
||||
channel = spice_new0(Channel, 1);
|
||||
channel->type = SPICE_CHANNEL_INPUTS;
|
||||
channel->link = inputs_link;
|
||||
channel->shutdown = inputs_shutdown;
|
||||
@ -2918,11 +2901,7 @@ static void reds_handle_read_header_done(void *opaque)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(link->link_mess = malloc(header->size))) {
|
||||
red_printf("malloc failed %u", header->size);
|
||||
reds_release_link(link);
|
||||
return;
|
||||
}
|
||||
link->link_mess = spice_malloc(header->size);
|
||||
|
||||
obj->now = (uint8_t *)link->link_mess;
|
||||
obj->end = obj->now + header->size;
|
||||
@ -2975,40 +2954,27 @@ static RedLinkInfo *__reds_accept_connection(int listen_socket)
|
||||
|
||||
if ((flags = fcntl(socket, F_GETFL)) == -1) {
|
||||
red_printf("accept failed, %s", strerror(errno));
|
||||
goto error1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (fcntl(socket, F_SETFL, flags | O_NONBLOCK) == -1) {
|
||||
red_printf("accept failed, %s", strerror(errno));
|
||||
goto error1;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (setsockopt(socket, IPPROTO_TCP, TCP_NODELAY, &delay_val, sizeof(delay_val)) == -1) {
|
||||
red_printf("setsockopt failed, %s", strerror(errno));
|
||||
}
|
||||
|
||||
if (!(link = malloc(sizeof(RedLinkInfo)))) {
|
||||
red_printf("malloc failed");
|
||||
goto error1;
|
||||
}
|
||||
|
||||
if (!(peer = malloc(sizeof(RedsStreamContext)))) {
|
||||
red_printf("malloc failed");
|
||||
goto error2;
|
||||
}
|
||||
|
||||
memset(link, 0, sizeof(RedLinkInfo));
|
||||
memset(peer, 0, sizeof(RedsStreamContext));
|
||||
link = spice_new0(RedLinkInfo, 1);
|
||||
peer = spice_new0(RedsStreamContext, 1);
|
||||
link->peer = peer;
|
||||
peer->socket = socket;
|
||||
openssl_init(link);
|
||||
|
||||
return link;
|
||||
|
||||
error2:
|
||||
free(link);
|
||||
|
||||
error1:
|
||||
error:
|
||||
close(socket);
|
||||
|
||||
return NULL;
|
||||
@ -3469,8 +3435,7 @@ static void reds_do_set_ticket(const char *password, const char *args)
|
||||
int option;
|
||||
char *val;
|
||||
|
||||
in_args = local_args = malloc(strlen(args) + 1);
|
||||
strcpy(local_args, args);
|
||||
in_args = local_args = spice_strdup(args);
|
||||
do {
|
||||
switch (option = get_option(&in_args, &val, _spice_ticket_options, ',')) {
|
||||
case SPICE_TICKET_OPTION_EXPIRATION: {
|
||||
@ -3836,10 +3801,7 @@ static void set_one_channel_security(int id, uint32_t security)
|
||||
security_options->options = security;
|
||||
return;
|
||||
}
|
||||
security_options = (ChannelSecurityOptions *)malloc(sizeof(*security_options));
|
||||
if (!security_options) {
|
||||
red_error("malloc failed");
|
||||
}
|
||||
security_options = spice_new(ChannelSecurityOptions, 1);
|
||||
security_options->channel_id = id;
|
||||
security_options->options = security;
|
||||
security_options->next = channels_security;
|
||||
@ -3848,17 +3810,14 @@ static void set_one_channel_security(int id, uint32_t security)
|
||||
|
||||
static int set_channels_security(const char *channels, uint32_t security)
|
||||
{
|
||||
char *local_str = malloc(strlen(channels) + 1);
|
||||
char *local_str;
|
||||
int channel_name;
|
||||
char *str;
|
||||
char *val;
|
||||
int all = 0;
|
||||
int specific = 0;
|
||||
|
||||
if (!local_str) {
|
||||
red_error("malloc failed");
|
||||
}
|
||||
strcpy(local_str, channels);
|
||||
local_str = spice_strdup(channels);
|
||||
str = local_str;
|
||||
do {
|
||||
switch (channel_name = get_option(&str, &val, _channel_map, '+')) {
|
||||
@ -3928,8 +3887,7 @@ int __attribute__ ((visibility ("default"))) spice_parse_args(const char *in_arg
|
||||
|
||||
memset(&ssl_parameters, 0, sizeof(ssl_parameters));
|
||||
|
||||
local_args = malloc(strlen(in_args) + 1);
|
||||
strcpy(local_args, in_args);
|
||||
local_args = spice_strdup(in_args);
|
||||
|
||||
args = local_args;
|
||||
do {
|
||||
@ -4394,14 +4352,7 @@ static void reds_mig_send_ticket(RedsMigSpice *s)
|
||||
|
||||
static void reds_mig_receive_cert_public_key(RedsMigSpice *s)
|
||||
{
|
||||
s->cert_pub_key = malloc(s->cert_pub_key_len);
|
||||
if (!s->cert_pub_key) {
|
||||
red_printf("alloc failed");
|
||||
reds_mig_failed(s);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(s->cert_pub_key, s->read.buf, s->cert_pub_key_len);
|
||||
s->cert_pub_key = spice_memdup(s->read.buf, s->cert_pub_key_len);
|
||||
|
||||
s->read.size = SPICE_TICKET_PUBKEY_BYTES;
|
||||
s->read.end_pos = 0;
|
||||
@ -4530,21 +4481,12 @@ static void reds_mig_started(void *opaque, const char *in_args)
|
||||
goto error;
|
||||
}
|
||||
|
||||
spice_migration = (RedsMigSpice *)malloc(sizeof(RedsMigSpice));
|
||||
if (!spice_migration) {
|
||||
red_printf("Could not allocate memory for spice migration structure");
|
||||
goto error;
|
||||
}
|
||||
memset(spice_migration, 0, sizeof(RedsMigSpice));
|
||||
spice_migration = spice_new0(RedsMigSpice, 1);
|
||||
spice_migration->port = -1;
|
||||
spice_migration->sport = -1;
|
||||
|
||||
if (!(spice_migration->local_args = malloc(strlen(in_args) + 1))) {
|
||||
red_printf("str malloc failed");
|
||||
goto error;
|
||||
}
|
||||
spice_migration->local_args = spice_strdup(in_args);
|
||||
|
||||
strcpy(spice_migration->local_args, in_args);
|
||||
args = spice_migration->local_args;
|
||||
do {
|
||||
switch (option = get_option(&args, &val, spice_mig_options, ',')) {
|
||||
@ -5351,11 +5293,7 @@ static void init_vd_agent_resources()
|
||||
state->recive_len = sizeof(state->vdi_chunk_header);
|
||||
|
||||
for (i = 0; i < REDS_AGENT_WINDOW_SIZE; i++) {
|
||||
VDAgentExtBuf *buf = (VDAgentExtBuf *)malloc(sizeof(VDAgentExtBuf));
|
||||
if (!buf) {
|
||||
PANIC("alloc failed");
|
||||
}
|
||||
memset(buf, 0, sizeof(*buf));
|
||||
VDAgentExtBuf *buf = spice_new0(VDAgentExtBuf, 1);
|
||||
ring_item_init(&buf->base.link);
|
||||
buf->base.chunk_header.port = VDP_CLIENT_PORT;
|
||||
buf->base.free = free_external_agent_buff;
|
||||
@ -5363,11 +5301,7 @@ static void init_vd_agent_resources()
|
||||
}
|
||||
|
||||
for (i = 0; i < REDS_NUM_INTERNAL_AGENT_MESSAGES; i++) {
|
||||
VDInternalBuf *buf = (VDInternalBuf *)malloc(sizeof(VDInternalBuf));
|
||||
if (!buf) {
|
||||
PANIC("alloc failed");
|
||||
}
|
||||
memset(buf, 0, sizeof(*buf));
|
||||
VDInternalBuf *buf = spice_new0(VDInternalBuf, 1);
|
||||
ring_item_init(&buf->base.link);
|
||||
buf->base.free = free_internal_agent_buff;
|
||||
buf->base.chunk_header.port = VDP_SERVER_PORT;
|
||||
@ -5380,11 +5314,7 @@ static void init_vd_agent_resources()
|
||||
}
|
||||
|
||||
for (i = 0; i < REDS_VDI_PORT_NUM_RECIVE_BUFFS; i++) {
|
||||
VDIReadBuf *buf = (VDIReadBuf *)malloc(sizeof(VDIReadBuf));
|
||||
if (!buf) {
|
||||
PANIC("alloc failed");
|
||||
}
|
||||
memset(buf, 0, sizeof(*buf));
|
||||
VDIReadBuf *buf = spice_new0(VDIReadBuf, 1);
|
||||
buf->out_item.prepare = reds_prepare_read_buf;
|
||||
buf->out_item.release = reds_release_read_buf;
|
||||
buf->header.type = SPICE_MSG_MAIN_AGENT_DATA;
|
||||
@ -5446,9 +5376,7 @@ static void do_spice_init(CoreInterface *core_interface)
|
||||
int shm_name_len = strlen(SPICE_STAT_SHM_NAME) + 20;
|
||||
int fd;
|
||||
|
||||
if (!(reds->stat_shm_name = (char *)malloc(shm_name_len))) {
|
||||
red_error("stat_shm_name alloc failed");
|
||||
}
|
||||
reds->stat_shm_name = (char *)spice_malloc(shm_name_len);
|
||||
snprintf(reds->stat_shm_name, shm_name_len, SPICE_STAT_SHM_NAME, getpid());
|
||||
if ((fd = shm_open(reds->stat_shm_name, O_CREAT | O_RDWR, 0444)) == -1) {
|
||||
red_error("statistics shm_open failed, %s", strerror(errno));
|
||||
@ -5500,10 +5428,7 @@ SpiceServer *spice_server_new(void)
|
||||
/* we can't handle multiple instances (yet) */
|
||||
ASSERT(reds == NULL);
|
||||
|
||||
if (!(reds = malloc(sizeof(RedsState)))) {
|
||||
red_error("reds alloc failed");
|
||||
}
|
||||
memset(reds, 0, sizeof(RedsState));
|
||||
reds = spice_new0(RedsState, 1);
|
||||
return reds;
|
||||
}
|
||||
|
||||
|
||||
@ -795,11 +795,7 @@ static SndChannel *__new_channel(SndWorker *worker, int size, RedsStreamContext
|
||||
}
|
||||
|
||||
ASSERT(size >= sizeof(*channel));
|
||||
if (!(channel = malloc(size))) {
|
||||
red_printf("malloc failed");
|
||||
goto error1;
|
||||
}
|
||||
memset(channel, 0, size);
|
||||
channel = spice_malloc0(size);
|
||||
channel->peer = peer;
|
||||
channel->worker = worker;
|
||||
channel->recive_data.message = (SpiceDataHeader *)channel->recive_data.buf;
|
||||
@ -1201,10 +1197,7 @@ static SndWorker *find_worker(VDInterface *interface)
|
||||
void snd_attach_playback(PlaybackInterface *interface)
|
||||
{
|
||||
SndWorker *playback_worker;
|
||||
if (!(playback_worker = (SndWorker *)malloc(sizeof(*playback_worker)))) {
|
||||
red_error("playback channel malloc failed");
|
||||
}
|
||||
memset(playback_worker, 0, sizeof(*playback_worker));
|
||||
playback_worker = spice_new0(SndWorker, 1);
|
||||
playback_worker->base.type = SPICE_CHANNEL_PLAYBACK;
|
||||
playback_worker->base.link = snd_set_playback_peer;
|
||||
playback_worker->base.shutdown = snd_shutdown;
|
||||
@ -1213,9 +1206,7 @@ void snd_attach_playback(PlaybackInterface *interface)
|
||||
|
||||
playback_worker->interface = &interface->base;
|
||||
playback_worker->base.num_caps = 1;
|
||||
if (!(playback_worker->base.caps = malloc(sizeof(uint32_t)))) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
playback_worker->base.caps = spice_new(uint32_t, 1);
|
||||
playback_worker->base.caps[0] = (1 << SPICE_PLAYBACK_CAP_CELT_0_5_1);
|
||||
|
||||
add_worker(playback_worker);
|
||||
@ -1225,11 +1216,7 @@ void snd_attach_playback(PlaybackInterface *interface)
|
||||
void snd_attach_record(RecordInterface *interface)
|
||||
{
|
||||
SndWorker *record_worker;
|
||||
if (!(record_worker = (SndWorker *)malloc(sizeof(*record_worker)))) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
|
||||
memset(record_worker, 0, sizeof(*record_worker));
|
||||
record_worker = spice_new0(SndWorker, 1);
|
||||
record_worker->base.type = SPICE_CHANNEL_RECORD;
|
||||
record_worker->base.link = snd_set_record_peer;
|
||||
record_worker->base.shutdown = snd_shutdown;
|
||||
@ -1239,9 +1226,7 @@ void snd_attach_record(RecordInterface *interface)
|
||||
record_worker->interface = &interface->base;
|
||||
|
||||
record_worker->base.num_caps = 1;
|
||||
if (!(record_worker->base.caps = malloc(sizeof(uint32_t)))) {
|
||||
PANIC("malloc failed");
|
||||
}
|
||||
record_worker->base.caps = spice_new(uint32_t, 1);
|
||||
record_worker->base.caps[0] = (1 << SPICE_RECORD_CAP_CELT_0_5_1);
|
||||
add_worker(record_worker);
|
||||
reds_register_channel(&record_worker->base);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user