glib replacement: removed any use of glib functions

This commit is contained in:
Alexander Pevzner
2020-07-25 01:50:14 +03:00
parent 3ce70a3b3b
commit 86b1badc11
21 changed files with 280 additions and 238 deletions
+2 -2
View File
@@ -59,7 +59,7 @@ static void
image_decoder_bmp_free (image_decoder *decoder)
{
image_decoder_bmp *bmp = (image_decoder_bmp*) decoder;
g_free(bmp);
mem_free(bmp);
}
/* Begin BMP decoding
@@ -275,7 +275,7 @@ image_decoder_bmp_read_line (image_decoder *decoder, void *buffer)
image_decoder*
image_decoder_bmp_new (void)
{
image_decoder_bmp *bmp = g_new0(image_decoder_bmp, 1);
image_decoder_bmp *bmp = mem_new(image_decoder_bmp, 1);
bmp->decoder.content_type = "image/bmp";
bmp->decoder.free = image_decoder_bmp_free;
+3 -3
View File
@@ -15,7 +15,7 @@
devcaps_source*
devcaps_source_new (void)
{
devcaps_source *src = g_new0(devcaps_source, 1);
devcaps_source *src = mem_new(devcaps_source, 1);
src->resolutions = sane_word_array_new();
return src;
}
@@ -27,7 +27,7 @@ devcaps_source_free (devcaps_source *src)
{
if (src != NULL) {
sane_word_array_free(src->resolutions);
g_free(src);
mem_free(src);
}
}
@@ -36,7 +36,7 @@ devcaps_source_free (devcaps_source *src)
devcaps_source*
devcaps_source_clone (const devcaps_source *src)
{
devcaps_source *src2 = g_new0(devcaps_source, 1);
devcaps_source *src2 = mem_new(devcaps_source, 1);
unsigned int i, len;
*src2 = *src;
+7 -7
View File
@@ -181,7 +181,7 @@ device_new (zeroconf_devinfo *devinfo)
device *dev;
/* Create device */
dev = g_new0(device, 1);
dev = mem_new(device, 1);
dev->devinfo = devinfo;
dev->log = log_ctx_new(dev->devinfo->name, NULL);
@@ -235,7 +235,7 @@ device_free (device *dev)
http_client_free(dev->proto_ctx.http);
http_uri_free(dev->proto_ctx.base_uri_nozone);
g_free((char*) dev->proto_ctx.location);
mem_free((char*) dev->proto_ctx.location);
pthread_cond_destroy(&dev->stm_cond);
@@ -253,7 +253,7 @@ device_free (device *dev)
log_debug(dev->log, "device destroyed");
log_ctx_free(dev->log);
zeroconf_devinfo_free(dev->devinfo);
g_free(dev);
mem_free(dev);
}
/* Start probing. Called via eloop_call
@@ -750,7 +750,7 @@ device_stm_op_callback (void *ptr, http_query *q)
/* Save useful result, if any */
if (dev->proto_op_current == PROTO_OP_SCAN) {
if (result.data.location != NULL) {
g_free((char*) dev->proto_ctx.location); /* Just in case */
mem_free((char*) dev->proto_ctx.location); /* Just in case */
dev->proto_ctx.location = result.data.location;
dev->proto_ctx.failed_attempt = 0;
pthread_cond_broadcast(&dev->stm_cond);
@@ -1175,7 +1175,7 @@ device_start_new_job (device *dev)
{
dev->stm_cancel_sent = false;
dev->job_status = SANE_STATUS_GOOD;
g_free((char*) dev->proto_ctx.location);
mem_free((char*) dev->proto_ctx.location);
dev->proto_ctx.location = NULL;
dev->proto_ctx.failed_op = PROTO_OP_NONE;
dev->proto_ctx.failed_attempt = 0;
@@ -1413,7 +1413,7 @@ device_read_next (device *dev)
}
/* Initialize image decoding */
dev->read_line_buf = g_malloc(line_capacity);
dev->read_line_buf = mem_new(SANE_Byte, line_capacity);
memset(dev->read_line_buf, 0xff, line_capacity);
dev->read_line_num = 0;
@@ -1616,7 +1616,7 @@ DONE:
http_data_unref(dev->read_image);
dev->read_image = NULL;
}
g_free(dev->read_line_buf);
mem_free(dev->read_line_buf);
dev->read_line_buf = NULL;
if (device_stm_state_get(dev) == DEVICE_STM_DONE &&
+9 -9
View File
@@ -256,7 +256,7 @@ eloop_call_execute (void)
pending = OUTER_STRUCT(node, eloop_call_pending, node);
pending->func(pending->data);
g_free(pending);
mem_free(pending);
}
}
@@ -265,7 +265,7 @@ eloop_call_execute (void)
void
eloop_call (GSourceFunc func, gpointer data)
{
eloop_call_pending *p = g_new0(eloop_call_pending, 1);
eloop_call_pending *p = mem_new(eloop_call_pending, 1);
p->func = func;
p->data = data;
@@ -316,7 +316,7 @@ eloop_event_new (void (*callback)(void *), void *data)
return NULL;
}
event = g_new0(eloop_event, 1);
event = mem_new(eloop_event, 1);
event->p = p;
event->callback = callback;
event->data = data;
@@ -372,7 +372,7 @@ eloop_timer*
eloop_timer_new (int timeout, void (*callback)(void *), void *data)
{
const AvahiPoll *poll = eloop_poll_get();
eloop_timer *timer = g_new0(eloop_timer, 1);
eloop_timer *timer = mem_new(eloop_timer, 1);
struct timeval end;
avahi_elapse_time(&end, timeout, 0);
@@ -395,7 +395,7 @@ eloop_timer_cancel (eloop_timer *timer)
const AvahiPoll *poll = eloop_poll_get();
poll->timeout_free(timer->timeout);
g_free(timer);
mem_free(timer);
}
/* eloop_fdpoll notifies user when file becomes
@@ -446,7 +446,7 @@ eloop_fdpoll_new (int fd,
void (*callback) (int, void*, ELOOP_FDPOLL_MASK), void *data)
{
const AvahiPoll *poll = eloop_poll_get();
eloop_fdpoll *fdpoll = g_new0(eloop_fdpoll, 1);
eloop_fdpoll *fdpoll = mem_new(eloop_fdpoll, 1);
fdpoll->fd = fd;
fdpoll->callback = callback;
@@ -466,7 +466,7 @@ eloop_fdpoll_free (eloop_fdpoll *fdpoll)
const AvahiPoll *poll = eloop_poll_get();
poll->watch_free(fdpoll->watch);
g_free(fdpoll);
mem_free(fdpoll);
}
/* Set eloop_fdpoll event mask
@@ -514,10 +514,10 @@ eloop_eprintf(const char *fmt, ...)
log_assert(NULL, pthread_equal(pthread_self(), eloop_thread));
va_start(ap, fmt);
estring = g_strdup_vprintf(fmt, ap);
estring = str_vprintf(fmt, ap);
va_end(ap);
g_free(eloop_estring);
mem_free(eloop_estring);
eloop_estring = estring;
return ERROR(estring);
+5 -5
View File
@@ -632,7 +632,7 @@ escl_scan_decode (const proto_ctx *ctx)
goto ERROR;
}
result.data.location = g_strdup(http_uri_get_path(uri));
result.data.location = str_dup(http_uri_get_path(uri));
http_uri_free(uri);
result.next = PROTO_OP_LOAD;
@@ -655,10 +655,10 @@ escl_load_query (const proto_ctx *ctx)
http_query *q;
sep = str_has_suffix(ctx->location, "/") ? "" : "/";
url = g_strconcat(ctx->location, sep, "NextDocument", NULL);
url = str_concat(ctx->location, sep, "NextDocument", NULL);
q = escl_http_get(ctx, url);
g_free(url);
mem_free(url);
return q;
}
@@ -907,7 +907,7 @@ escl_cancel_query (const proto_ctx *ctx)
static void
escl_free (proto_handler *proto)
{
g_free(proto);
mem_free(proto);
}
/* proto_handler_escl_new creates new eSCL protocol handler
@@ -915,7 +915,7 @@ escl_free (proto_handler *proto)
proto_handler*
proto_handler_escl_new (void)
{
proto_handler_escl *escl = g_new0(proto_handler_escl, 1);
proto_handler_escl *escl = mem_new(proto_handler_escl, 1);
escl->proto.name = "eSCL";
escl->proto.free = escl_free;
+32 -37
View File
@@ -156,7 +156,7 @@ static char*
http_uri_field_strdup (const http_uri *uri, int num)
{
http_uri_field field = http_uri_field_get(uri, num);
char *s = g_malloc(field.len + 1);
char *s = mem_new(char, field.len + 1);
memcpy(s, field.str, field.len);
s[field.len] = '\0';
@@ -250,10 +250,10 @@ http_uri_field_replace (http_uri *uri, int num, const char *val)
uri2 = http_uri_new(buf, false);
log_assert(NULL, uri2 != NULL);
g_free((char*) uri->str);
g_free((char*) uri->path);
mem_free((char*) uri->str);
mem_free((char*) uri->path);
*uri = *uri2;
g_free(uri2);
mem_free(uri2);
}
/* Append UF_PATH part of URI to buffer up to the final '/'
@@ -479,7 +479,7 @@ http_uri_parse_addr (http_uri *uri)
http_uri*
http_uri_new (const char *str, bool strip_fragment)
{
http_uri *uri = g_new0(http_uri, 1);
http_uri *uri = mem_new(http_uri, 1);
char *buf;
/* Parse URI */
@@ -497,7 +497,7 @@ http_uri_new (const char *str, bool strip_fragment)
goto FAIL;
}
uri->str = buf = g_strdup(str);
uri->str = buf = str_dup(str);
/* Honor strip_fragment flag */
if (strip_fragment && http_uri_field_present(uri, UF_FRAGMENT)) {
@@ -515,7 +515,7 @@ http_uri_new (const char *str, bool strip_fragment)
/* Error: cleanup and exit */
FAIL:
g_free(uri);
mem_free(uri);
return NULL;
}
@@ -524,11 +524,11 @@ FAIL:
http_uri*
http_uri_clone (const http_uri *old)
{
http_uri *uri = g_new0(http_uri, 1);
http_uri *uri = mem_new(http_uri, 1);
*uri = *old;
uri->str = g_strdup(uri->str);
uri->path = g_strdup(uri->path);
uri->str = str_dup(uri->str);
uri->path = str_dup(uri->path);
return uri;
}
@@ -736,9 +736,9 @@ void
http_uri_free (http_uri *uri)
{
if (uri != NULL) {
g_free((char*) uri->str);
g_free((char*) uri->path);
g_free(uri);
mem_free((char*) uri->str);
mem_free((char*) uri->path);
mem_free(uri);
}
}
#endif
@@ -897,7 +897,7 @@ typedef struct {
static http_hdr_field*
http_hdr_field_new (const char *name)
{
http_hdr_field *field = g_new0(http_hdr_field, 1);
http_hdr_field *field = mem_new(http_hdr_field, 1);
field->name = name ? str_dup(name) : str_new();
return field;
}
@@ -909,7 +909,7 @@ http_hdr_field_free (http_hdr_field *field)
{
mem_free(field->name);
mem_free(field->value);
g_free(field);
mem_free(field);
}
/* Initialize http_hdr in place
@@ -1307,14 +1307,9 @@ struct http_multipart {
/* Add multipart body
*/
static void
http_multipart_add_body (http_multipart *mp, http_data *body) {
/* Expand bodies array, if size is zero or reached power of two */
if (!(mp->count & (mp->count - 1))) {
int cap = mp->count ? mp->count * 2 : 4;
mp->bodies = g_renew(http_data*, mp->bodies, cap);
}
/* Append new body */
http_multipart_add_body (http_multipart *mp, http_data *body)
{
mp->bodies = mem_resize(mp->bodies, mp->count + 1, 0);
mp->bodies[mp->count ++] = body;
}
@@ -1391,7 +1386,7 @@ http_multipart_free (http_multipart *mp)
http_data_unref(mp->bodies[i]);
}
g_free(mp);
mem_free(mp);
}
/* Parse MIME multipart message body
@@ -1436,7 +1431,7 @@ http_multipart_parse (http_data *data, const char *content_type)
}
/* Create http_multipart structure */
mp = g_new0(http_multipart, 1);
mp = mem_new(http_multipart, 1);
mp->data = http_data_ref(data);
/* Split data into parts */
@@ -1494,7 +1489,7 @@ typedef struct {
static http_data*
http_data_new(http_data *parent, const char *bytes, size_t size)
{
http_data_ex *data_ex = g_new0(http_data_ex, 1);
http_data_ex *data_ex = mem_new(http_data_ex, 1);
if (parent != NULL) {
log_assert(NULL, bytes >= (char*) parent->bytes);
@@ -1502,7 +1497,7 @@ http_data_new(http_data *parent, const char *bytes, size_t size)
(bytes + size) <= ((char*) parent->bytes + parent->size));
}
data_ex->data.content_type = g_strdup("");
data_ex->data.content_type = str_new();
data_ex->data.bytes = bytes;
data_ex->data.size = size;
@@ -1517,14 +1512,14 @@ http_data_new(http_data *parent, const char *bytes, size_t size)
static void
http_data_set_content_type (http_data *data, const char *content_type)
{
g_free((char*) data->content_type);
mem_free((char*) data->content_type);
if (content_type == NULL) {
content_type = "text/plain";
} else {
char *s;
content_type = g_ascii_strdown(content_type, -1);
content_type = str_dup_tolower(content_type);
s = strchr(content_type, ';');
if (s != NULL) {
*s = '\0';
@@ -1556,11 +1551,11 @@ http_data_unref (http_data *data)
if (data_ex->parent != NULL) {
http_data_unref(data_ex->parent);
} else {
g_free((void*) data_ex->data.bytes);
mem_free((void*) data_ex->data.bytes);
}
g_free((char*) data_ex->data.content_type);
g_free(data_ex);
mem_free((char*) data_ex->data.content_type);
mem_free(data_ex);
}
}
}
@@ -1575,7 +1570,7 @@ http_data_append (http_data *data, const char *bytes, size_t size)
log_assert(NULL, data_ex->parent == NULL);
data->bytes = g_realloc((char*) data->bytes, data->size + size);
data->bytes = mem_resize((char*) data->bytes, data->size + size, 0);
memcpy((char*) data->bytes + data->size, bytes, size);
data->size += size;
}
@@ -1659,7 +1654,7 @@ struct http_client {
http_client*
http_client_new (log_ctx *log, void *ptr)
{
http_client *client = g_new0(http_client, 1);
http_client *client = mem_new(http_client, 1);
client->ptr = ptr;
client->log = log;
@@ -1675,7 +1670,7 @@ http_client_free (http_client *client)
{
log_assert(client->log, ll_empty(&client->pending));
g_free(client);
mem_free(client);
}
/* Set on-error callback. If this callback is not NULL,
@@ -1819,7 +1814,7 @@ http_query_free (http_query *q)
http_multipart_free(q->response_multipart);
}
g_free(q);
mem_free(q);
}
/* Set Host header in HTTP request
@@ -1876,7 +1871,7 @@ http_query*
http_query_new (http_client *client, http_uri *uri, const char *method,
char *body, const char *content_type)
{
http_query *q = g_new0(http_query, 1);
http_query *q = mem_new(http_query, 1);
q->client = client;
q->uri = uri;
+12 -17
View File
@@ -123,7 +123,6 @@ ip_is_loopback (int af, const void *addr)
*/
struct ip_addrset {
ip_addr *addrs; /* Addresses in the set */
size_t len, cap; /* Set length and capacity */
};
/* Create new ip_addrset
@@ -131,11 +130,8 @@ struct ip_addrset {
ip_addrset*
ip_addrset_new (void)
{
ip_addrset *addrset = g_new0(ip_addrset, 1);
addrset->cap = 4;
addrset->addrs = g_new(ip_addr, addrset->cap);
ip_addrset *addrset = mem_new(ip_addrset, 1);
addrset->addrs = mem_new(ip_addr, 0);
return addrset;
}
@@ -144,8 +140,8 @@ ip_addrset_new (void)
void
ip_addrset_free (ip_addrset *addrset)
{
g_free(addrset->addrs);
g_free(addrset);
mem_free(addrset->addrs);
mem_free(addrset);
}
/* Find address index within a set. Returns -1 if address was not found
@@ -153,9 +149,9 @@ ip_addrset_free (ip_addrset *addrset)
static int
ip_addrset_index (const ip_addrset *addrset, ip_addr addr)
{
size_t i;
size_t i, len = mem_len(addrset->addrs);
for (i = 0; i < addrset->len; i ++) {
for (i = 0; i < len; i ++) {
if (ip_addr_equal(addrset->addrs[i], addr)) {
return (int) i;
}
@@ -191,12 +187,10 @@ ip_addrset_add (ip_addrset *addrset, ip_addr addr)
void
ip_addrset_add_unsafe (ip_addrset *addrset, ip_addr addr)
{
if (addrset->len == addrset->cap) {
addrset->cap *= 2;
addrset->addrs = g_renew(ip_addr, addrset->addrs, addrset->cap);
}
size_t len = mem_len(addrset->addrs);
addrset->addrs[addrset->len ++] = addr;
addrset->addrs = mem_resize(addrset->addrs, len + 1, 0);
addrset->addrs[len] = addr;
}
/* Del address from the set.
@@ -207,12 +201,13 @@ ip_addrset_del (ip_addrset *addrset, ip_addr addr)
int i = ip_addrset_index(addrset, addr);
if (i >= 0) {
size_t tail = addrset->len - (size_t) i - 1;
size_t len = mem_len(addrset->addrs);
size_t tail = len - (size_t) i - 1;
if (tail != 0) {
tail *= sizeof(*addrset->addrs);
memmove(&addrset->addrs[i], &addrset->addrs[i + 1], tail);
}
addrset->len --;
mem_shrink(addrset->addrs, len - 1);
}
}
+2 -2
View File
@@ -32,7 +32,7 @@ image_decoder_jpeg_free (image_decoder *decoder)
image_decoder_jpeg *jpeg = (image_decoder_jpeg*) decoder;
jpeg_destroy_decompress(&jpeg->cinfo);
g_free(jpeg);
mem_free(jpeg);
}
/* Begin JPEG decoding
@@ -202,7 +202,7 @@ image_decoder_jpeg_error_exit (j_common_ptr cinfo)
image_decoder*
image_decoder_jpeg_new (void)
{
image_decoder_jpeg *jpeg = g_new0(image_decoder_jpeg, 1);
image_decoder_jpeg *jpeg = mem_new(image_decoder_jpeg, 1);
jpeg->decoder.content_type = "image/jpeg";
jpeg->decoder.free = image_decoder_jpeg_free;
+4 -4
View File
@@ -114,9 +114,9 @@ struct log_ctx {
log_ctx*
log_ctx_new (const char *name, log_ctx *parent)
{
log_ctx *log = g_new0(log_ctx, 1);
log_ctx *log = mem_new(log_ctx, 1);
log->name = str_trim(g_strdup(name));
log->name = str_trim(str_dup(name));
if (parent != NULL) {
log->trace = trace_ref(parent->trace);
@@ -133,8 +133,8 @@ void
log_ctx_free (log_ctx *log)
{
trace_unref(log->trace);
g_free((char*) log->name);
g_free(log);
mem_free((char*) log->name);
mem_free(log);
}
/* Get protocol trace associated with logging context
+11 -12
View File
@@ -244,11 +244,11 @@ static mdns_finding*
mdns_finding_new (ZEROCONF_METHOD method, int ifindex, const char *name,
bool initscan)
{
mdns_finding *mdns = g_new0(mdns_finding, 1);
mdns_finding *mdns = mem_new(mdns_finding, 1);
mdns->finding.method = method;
mdns->finding.ifindex = ifindex;
mdns->finding.name = g_strdup(name);
mdns->finding.name = str_dup(name);
mdns->resolvers = ptr_array_new(AvahiServiceResolver*);
@@ -265,8 +265,8 @@ mdns_finding_new (ZEROCONF_METHOD method, int ifindex, const char *name,
static void
mdns_finding_free (mdns_finding *mdns)
{
g_free((char*) mdns->finding.name);
g_free((char*) mdns->finding.model);
mem_free((char*) mdns->finding.name);
mem_free((char*) mdns->finding.model);
zeroconf_endpoint_list_free(mdns->finding.endpoints);
if (mdns->initscan) {
@@ -274,7 +274,7 @@ mdns_finding_free (mdns_finding *mdns)
}
mem_free(mdns->resolvers);
g_free(mdns);
mem_free(mdns);
}
/* Find mdns_finding
@@ -416,18 +416,17 @@ mdns_make_escl_endpoint (ZEROCONF_METHOD method, const AvahiAddress *addr,
/* Make eSCL URL */
if (rs == NULL) {
/* Assume /eSCL by default */
u = g_strdup_printf("%s://%s:%d/eSCL/", scheme, str_addr, port);
u = str_printf("%s://%s:%d/eSCL/", scheme, str_addr, port);
} else if (rs_len == 0) {
/* Empty rs, avoid double '/' */
u = g_strdup_printf("%s://%s:%d/", scheme, str_addr, port);
u = str_printf("%s://%s:%d/", scheme, str_addr, port);
} else {
u = g_strdup_printf("%s://%s:%d/%.*s/", scheme, str_addr, port,
rs_len, rs);
u = str_printf("%s://%s:%d/%.*s/", scheme, str_addr, port, rs_len, rs);
}
uri = http_uri_new(u, true);
log_assert(mdns_log, uri != NULL);
g_free(u);
mem_free(u);
return zeroconf_endpoint_new(ID_PROTO_ESCL, uri);
}
@@ -486,7 +485,7 @@ mdns_avahi_resolver_found (mdns_finding *mdns, MDNS_SERVICE service,
/* Update finding */
if (mdns->finding.model == NULL && txt_ty != NULL) {
mdns->finding.model = g_strdup(txt_ty);
mdns->finding.model = str_dup(txt_ty);
}
if (!uuid_valid(mdns->finding.uuid) && txt_uuid != NULL) {
@@ -580,7 +579,7 @@ mdns_avahi_resolver_callback (AvahiServiceResolver *r,
/* Fixup model and UUID */
if (mdns->finding.model == NULL) {
/* Very unlikely, just paranoia */
mdns->finding.model = g_strdup(mdns->finding.name);
mdns->finding.model = str_dup(mdns->finding.name);
}
if (!uuid_valid(mdns->finding.uuid)) {
+60 -8
View File
@@ -64,7 +64,7 @@ mem_free (void *p)
size_t
mem_len_bytes (const void *p)
{
return ((mem_head*) p)[-1].len;
return p ? ((mem_head*) p)[-1].len : 0;
}
/* Get memory block capacity, in bytes
@@ -72,7 +72,7 @@ mem_len_bytes (const void *p)
size_t
mem_cap_bytes (const void *p)
{
return ((mem_head*) p)[-1].cap;
return p ? ((mem_head*) p)[-1].cap : 0;
}
/* Compute allocation size, including mem_head header, in bytes
@@ -172,6 +172,44 @@ __mem_shrink (void *p, size_t len, size_t elsize)
}
/******************** Strings ********************/
/* Create new string as a lowercase copy of existent string
*/
char*
str_dup_tolower (const char *s1)
{
char *s = str_dup(s1);
size_t i;
for (i = 0; s[i]; i ++) {
s[i] = safe_tolower(s[i]);
}
return s;
}
/* Create new string and print to it
*/
char*
str_printf (const char *format, ...)
{
va_list ap;
char *s;
va_start(ap, format);
s = str_append_vprintf(NULL, format, ap);
va_end(ap);
return s;
}
/* Create new string and print to it, va_list version
*/
char*
str_vprintf (const char *format, va_list ap)
{
return str_append_vprintf(NULL, format, ap);
}
/* Append formatted string to string
*
* `s' must be previously created by some of str_XXX functions,
@@ -180,14 +218,28 @@ __mem_shrink (void *p, size_t len, size_t elsize)
char*
str_append_printf (char *s, const char *format, ...)
{
char buf[4096];
va_list ap;
size_t len, oldlen;
va_start(ap, format);
len = vsnprintf(buf, sizeof(buf), format, ap);
s = str_append_vprintf(s, format, ap);
va_end(ap);
return s;
}
/* Append formatted string to string -- va_list version
*/
char*
str_append_vprintf (char *s, const char *format, va_list ap)
{
char buf[4096];
size_t len, oldlen;
va_list ap2;
va_copy(ap2, ap);
len = vsnprintf(buf, sizeof(buf), format, ap2);
va_end(ap2);
if (len < sizeof(buf)) {
return str_append_mem(s, buf, len);
}
@@ -195,9 +247,9 @@ str_append_printf (char *s, const char *format, ...)
oldlen = mem_len(s);
s = mem_resize(s, oldlen + len, 1);
va_start(ap, format);
vsnprintf(s + oldlen, len + 1, format, ap);
va_end(ap);
va_copy(ap2, ap);
vsnprintf(s + oldlen, len + 1, format, ap2);
va_end(ap2);
return s;
}
+5 -5
View File
@@ -153,7 +153,7 @@ netif_addr_list_get (void)
}
/* Translate struct ifaddrs to netif_addr */
addr = g_new0(netif_addr, 1);
addr = mem_new(netif_addr, 1);
addr->next = list;
addr->ifindex = idx;
strncpy(addr->ifname.text, ifa->ifa_name,
@@ -175,7 +175,7 @@ netif_addr_list_get (void)
default:
/* Paranoia; should not actually happen */
g_free(addr);
mem_free(addr);
addr = NULL;
break;
}
@@ -194,7 +194,7 @@ netif_addr_list_get (void)
static void
netif_addr_free_single (netif_addr *addr)
{
g_free(addr);
mem_free(addr);
}
/* Free list of network interfaces addresses
@@ -478,7 +478,7 @@ netif_notifier_read_callback (int fd, void *data, ELOOP_FDPOLL_MASK mask)
netif_notifier*
netif_notifier_create (void (*callback) (void*), void *data)
{
netif_notifier *notifier = g_new0(netif_notifier, 1);
netif_notifier *notifier = mem_new(netif_notifier, 1);
notifier->callback = callback;
notifier->data = data;
@@ -494,7 +494,7 @@ void
netif_notifier_free (netif_notifier *notifier)
{
ll_del(&notifier->list_node);
g_free(notifier);
mem_free(notifier);
}
/* Start/stop callback
+4 -4
View File
@@ -36,7 +36,7 @@ image_decoder_png_free (image_decoder *decoder)
image_decoder_png *png = (image_decoder_png*) decoder;
image_decoder_reset(decoder);
g_free(png);
mem_free(png);
}
/* libpng error callback
@@ -64,7 +64,7 @@ static void*
image_decoder_png_malloc_fn (png_struct *png_ptr, size_t size)
{
(void) png_ptr;
return g_malloc(size);
return mem_new(char, size);
}
/* libpng free callback
@@ -73,7 +73,7 @@ static void
image_decoder_png_free_fn (png_struct *png_ptr, void *p)
{
(void) png_ptr;
g_free(p);
mem_free(p);
}
/* libpng read callback
@@ -246,7 +246,7 @@ image_decoder_png_read_line (image_decoder *decoder, void *buffer)
image_decoder*
image_decoder_png_new (void)
{
image_decoder_png *png = g_new0(image_decoder_png, 1);
image_decoder_png *png = mem_new(image_decoder_png, 1);
png->decoder.content_type = "image/png";
png->decoder.free = image_decoder_png_free;
+2 -2
View File
@@ -30,7 +30,7 @@ pollable_new (void)
return NULL;
}
pollable *p = g_new0(pollable, 1);
pollable *p = mem_new(pollable, 1);
p->efd = efd;
return p;
@@ -42,7 +42,7 @@ void
pollable_free (pollable *p)
{
close(p->efd);
g_free(p);
mem_free(p);
}
/* Get file descriptor for poll()/select().
+2 -2
View File
@@ -91,7 +91,7 @@ trace_open (const char *device_name)
}
os_mkdir(conf.dbg_trace, 0755);
t = g_new0(trace, 1);
t = mem_new(trace, 1);
t->refcnt = 1;
strcpy(path, conf.dbg_trace);
@@ -151,7 +151,7 @@ trace_unref (trace *t)
}
fclose(t->data);
}
g_free(t);
mem_free(t);
}
}
+6 -6
View File
@@ -73,7 +73,7 @@ typedef struct {
static void
wsd_free (proto_handler *proto)
{
g_free(proto);
mem_free(proto);
}
/* Create a HTTP POST request
@@ -793,8 +793,8 @@ wsd_scan_decode (const proto_ctx *ctx)
err = xml_rd_node_value_uint(xml, &job_id);
} else if (!strcmp(path, "s:Envelope/s:Body/scan:CreateScanJobResponse"
"/scan:JobToken")) {
g_free(job_token);
job_token = g_strdup(xml_rd_node_value(xml));
mem_free(job_token);
job_token = str_dup(xml_rd_node_value(xml));
}
xml_rd_deep_next(xml, 0);
@@ -811,12 +811,12 @@ wsd_scan_decode (const proto_ctx *ctx)
}
result.next = PROTO_OP_LOAD;
result.data.location = g_strdup_printf("%u:%s", job_id, job_token);
result.data.location = str_printf("%u:%s", job_id, job_token);
/* Cleanup and exit */
DONE:
xml_rd_finish(&xml);
g_free(job_token);
mem_free(job_token);
if (err != NULL) {
result.err = eloop_eprintf("CreateScanJobResponse: %s", ESTRING(err));
@@ -960,7 +960,7 @@ wsd_cancel_query (const proto_ctx *ctx)
proto_handler*
proto_handler_wsd_new (void)
{
proto_handler_wsd *wsd = g_new0(proto_handler_wsd, 1);
proto_handler_wsd *wsd = mem_new(proto_handler_wsd, 1);
wsd->proto.name = "WSD";
wsd->proto.free = wsd_free;
+26 -26
View File
@@ -170,7 +170,7 @@ static const xml_ns wsdd_ns_rules[] = {
static wsdd_xaddr*
wsdd_xaddr_new (http_uri *uri)
{
wsdd_xaddr *xaddr = g_new0(wsdd_xaddr, 1);
wsdd_xaddr *xaddr = mem_new(wsdd_xaddr, 1);
xaddr->uri = uri;
return xaddr;
}
@@ -181,7 +181,7 @@ static void
wsdd_xaddr_free (wsdd_xaddr *xaddr)
{
http_uri_free(xaddr->uri);
g_free(xaddr);
mem_free(xaddr);
}
/* Add wsdd_xaddr to the list.
@@ -247,7 +247,7 @@ wsdd_initscan_count_dec (void)
static wsdd_finding*
wsdd_finding_new (int ifindex, const char *address)
{
wsdd_finding *wsdd = g_new0(wsdd_finding, 1);
wsdd_finding *wsdd = mem_new(wsdd_finding, 1);
wsdd->finding.method = ZEROCONF_WSD;
wsdd->finding.uuid = uuid_parse(address);
@@ -256,7 +256,7 @@ wsdd_finding_new (int ifindex, const char *address)
}
wsdd->finding.ifindex = ifindex;
wsdd->address = g_strdup(address);
wsdd->address = str_dup(address);
ll_init(&wsdd->xaddrs);
wsdd->http_client = http_client_new(wsdd_log, wsdd);
@@ -280,11 +280,11 @@ wsdd_finding_free (wsdd_finding *wsdd)
}
zeroconf_endpoint_list_free(wsdd->finding.endpoints);
g_free((char*) wsdd->address);
mem_free((char*) wsdd->address);
wsdd_xaddr_list_purge(&wsdd->xaddrs);
g_free((char*) wsdd->finding.model);
g_free((char*) wsdd->finding.name);
g_free(wsdd);
mem_free((char*) wsdd->finding.model);
mem_free((char*) wsdd->finding.name);
mem_free(wsdd);
}
/* Publish wsdd_finding
@@ -600,12 +600,12 @@ wsdd_finding_get_metadata_callback (void *ptr, http_query *q)
} else if (!strcmp(path, "s:Envelope/s:Body/mex:Metadata/mex:MetadataSection"
"/devprof:ThisModel/devprof:Manufacturer")) {
if (manufacturer == NULL) {
manufacturer = g_strdup(xml_rd_node_value(xml));
manufacturer = str_dup(xml_rd_node_value(xml));
}
} else if (!strcmp(path, "s:Envelope/s:Body/mex:Metadata/mex:MetadataSection"
"/devprof:ThisModel/devprof:ModelName")) {
if (model == NULL) {
model = g_strdup(xml_rd_node_value(xml));
model = str_dup(xml_rd_node_value(xml));
}
}
@@ -614,7 +614,7 @@ wsdd_finding_get_metadata_callback (void *ptr, http_query *q)
if (wsdd->finding.model == NULL) {
if (model != NULL && manufacturer != NULL) {
wsdd->finding.model = g_strdup_printf("%s %s", manufacturer, model);
wsdd->finding.model = str_printf("%s %s", manufacturer, model);
} else if (model != NULL) {
wsdd->finding.model = model;
model = NULL;
@@ -622,7 +622,7 @@ wsdd_finding_get_metadata_callback (void *ptr, http_query *q)
wsdd->finding.model = manufacturer;
manufacturer = NULL;
} else {
wsdd->finding.model = g_strdup(wsdd->address);
wsdd->finding.model = str_dup(wsdd->address);
}
}
@@ -640,8 +640,8 @@ wsdd_finding_get_metadata_callback (void *ptr, http_query *q)
/* Cleanup and exit */
DONE:
xml_rd_finish(&xml);
g_free(model);
g_free(manufacturer);
mem_free(model);
mem_free(manufacturer);
if (http_client_has_pending(wsdd->http_client) == 0) {
wsdd_finding_publish_delay(wsdd);
@@ -660,7 +660,7 @@ wsdd_finding_get_metadata (wsdd_finding *wsdd, int ifindex, wsdd_xaddr *xaddr)
sprintf(wsdd_buf, wsdd_get_metadata_template, u.text, wsdd->address);
q = http_query_new(wsdd->http_client, http_uri_clone(xaddr->uri),
"POST", g_strdup(wsdd_buf), "application/soap+xml; charset=utf-8");
"POST", str_dup(wsdd_buf), "application/soap+xml; charset=utf-8");
http_query_set_uintptr(q, ifindex);
http_query_submit(q, wsdd_finding_get_metadata_callback);
@@ -686,11 +686,11 @@ wsdd_message_parse_endpoint (wsdd_message *msg, xml_rd *xml)
msg->is_scanner = !!strstr(val, "ScanDeviceType");
msg->is_printer = !!strstr(val, "PrintDeviceType");
} else if (!strcmp(path, "/d:XAddrs")) {
g_free(xaddrs_text);
xaddrs_text = g_strdup(xml_rd_node_value(xml));
mem_free(xaddrs_text);
xaddrs_text = str_dup(xml_rd_node_value(xml));
} else if (!strcmp(path, "/a:EndpointReference/a:Address")) {
g_free((char*) msg->address);
msg->address = g_strdup(xml_rd_node_value(xml));
mem_free((char*) msg->address);
msg->address = str_dup(xml_rd_node_value(xml));
}
xml_rd_deep_next(xml, level);
@@ -711,7 +711,7 @@ wsdd_message_parse_endpoint (wsdd_message *msg, xml_rd *xml)
}
}
g_free(xaddrs_text);
mem_free(xaddrs_text);
}
/* Parse WSDD message
@@ -719,7 +719,7 @@ wsdd_message_parse_endpoint (wsdd_message *msg, xml_rd *xml)
static wsdd_message*
wsdd_message_parse (const char *xml_text, size_t xml_len)
{
wsdd_message *msg = g_new0(wsdd_message, 1);
wsdd_message *msg = mem_new(wsdd_message, 1);
xml_rd *xml;
error err;
@@ -771,9 +771,9 @@ static void
wsdd_message_free (wsdd_message *msg)
{
if (msg != NULL) {
g_free((char*) msg->address);
mem_free((char*) msg->address);
wsdd_xaddr_list_purge(&msg->xaddrs);
g_free(msg);
mem_free(msg);
}
}
@@ -1038,7 +1038,7 @@ wsdd_resolver_send_probe (wsdd_resolver *resolver)
static wsdd_resolver*
wsdd_resolver_new (const netif_addr *addr, bool initscan)
{
wsdd_resolver *resolver = g_new0(wsdd_resolver, 1);
wsdd_resolver *resolver = mem_new(wsdd_resolver, 1);
int af = addr->ipv6 ? AF_INET6 : AF_INET;
const char *af_name = addr->ipv6 ? "AF_INET6" : "AF_INET";
int rc;
@@ -1187,7 +1187,7 @@ wsdd_resolver_free (wsdd_resolver *resolver)
eloop_timer_cancel(resolver->timer);
}
g_free(resolver);
mem_free(resolver);
}
/******************** Miscellaneous events ********************/
@@ -1341,7 +1341,7 @@ wsdd_send_directed_probe (int ifindex, int af, const void *addr)
/* Send prove request */
q = http_query_new(wsdd_http_client, uri,
"POST", g_strdup(wsdd_buf), "application/soap+xml; charset=utf-8");
"POST", str_dup(wsdd_buf), "application/soap+xml; charset=utf-8");
http_query_set_uintptr(q, ifindex);
http_query_submit(q, wsdd_send_directed_probe_callback);
}
+25 -47
View File
@@ -21,14 +21,11 @@ struct xml_rd {
const char *name; /* Name of current node */
char *path; /* Path to current node, /-separated */
size_t *pathlen; /* Stack of path lengths */
size_t pathlen_cap; /* pathlen capacity */
const xmlChar *text; /* Textual value of current node */
unsigned int depth; /* Depth of current node, 0 for root */
const xml_ns *subst_rules; /* Substitution rules */
xml_ns *subst_cache; /* In the cache, glob-style patterns are
replaced by exact-matching strings */
size_t subst_cache_len;/* Count of subst_cache elements */
size_t subst_cache_cap;/* subst_cache capacity */
replaced by exact-matching strings. */
};
/* Forward declarations */
@@ -118,12 +115,11 @@ xml_rd_begin (xml_rd **xml, const char *xml_text, size_t xml_len,
return ERROR("Failed to parse XML");
}
*xml = g_new0(xml_rd, 1);
*xml = mem_new(xml_rd, 1);
(*xml)->doc = doc;
(*xml)->node = xmlDocGetRootElement((*xml)->doc);
(*xml)->path = str_new();
(*xml)->pathlen_cap = 8;
(*xml)->pathlen = g_malloc(sizeof(*(*xml)->pathlen) * (*xml)->pathlen_cap);
(*xml)->pathlen = mem_new(size_t, 0);
(*xml)->subst_rules = ns;
xml_rd_skip_dummy(*xml);
@@ -144,16 +140,16 @@ xml_rd_finish (xml_rd **xml)
xml_rd_node_invalidate_value(*xml);
if ((*xml)->subst_cache != NULL) {
size_t i;
for (i = 0; i < (*xml)->subst_cache_len; i ++) {
g_free((char*) (*xml)->subst_cache[i].uri);
size_t i, len = mem_len((*xml)->subst_cache);
for (i = 0; i < len; i ++) {
mem_free((char*) (*xml)->subst_cache[i].uri);
}
g_free((*xml)->subst_cache);
mem_free((*xml)->subst_cache);
}
g_free((*xml)->pathlen);
mem_free((*xml)->pathlen);
mem_free((*xml)->path);
g_free(*xml);
mem_free(*xml);
*xml = NULL;
}
}
@@ -165,7 +161,7 @@ xml_rd_finish (xml_rd **xml)
static const char*
xml_rd_ns_subst_lookup(xml_rd *xml, const char *prefix, const char *href)
{
size_t i;
size_t i, len = mem_len(xml->subst_cache);
/* Substitution enabled? */
if (xml->subst_rules == NULL) {
@@ -173,7 +169,7 @@ xml_rd_ns_subst_lookup(xml_rd *xml, const char *prefix, const char *href)
}
/* Lookup cache first */
for (i = 0; i < xml->subst_cache_len; i ++) {
for (i = 0; i < len; i ++) {
if (!strcmp(href, xml->subst_cache[i].uri)) {
return xml->subst_cache[i].prefix;
}
@@ -185,20 +181,9 @@ xml_rd_ns_subst_lookup(xml_rd *xml, const char *prefix, const char *href)
prefix = xml->subst_rules[i].prefix;
/* Update cache. Grow it if required */
if (xml->subst_cache_len == xml->subst_cache_cap) {
if (xml->subst_cache_cap == 0) {
xml->subst_cache_cap = 4; /* Initial size */
} else {
xml->subst_cache_cap *= 2;
}
}
xml->subst_cache = g_realloc(xml->subst_cache,
sizeof(*xml->subst_cache) * xml->subst_cache_cap);
xml->subst_cache[xml->subst_cache_len].prefix = prefix;
xml->subst_cache[xml->subst_cache_len].uri = g_strdup(href);
xml->subst_cache_len ++;
xml->subst_cache = mem_resize(xml->subst_cache, len + 1, 0);
xml->subst_cache[len].prefix = prefix;
xml->subst_cache[len].uri = str_dup(href);
/* Break out of loop */
break;
@@ -259,14 +244,9 @@ xml_rd_enter (xml_rd *xml)
{
if (xml->node) {
/* Save current path length into pathlen stack */
if (xml->depth == xml->pathlen_cap) {
xml->pathlen_cap *= 2;
xml->pathlen = g_realloc(xml->pathlen,
sizeof(*xml->pathlen) * xml->pathlen_cap);
}
xml->path = str_append_c(xml->path, '/');
xml->pathlen = mem_resize(xml->pathlen, xml->depth, 0);
xml->pathlen[xml->depth] = mem_len(xml->path);
/* Enter the node */
@@ -389,11 +369,11 @@ struct xml_wr {
static xml_wr_node*
xml_wr_node_new (const char *name, const char *value, const xml_attr *attrs)
{
xml_wr_node *node = g_new0(xml_wr_node, 1);
node->name = g_strdup(name);
xml_wr_node *node = mem_new(xml_wr_node, 1);
node->name = str_dup(name);
node->attrs = attrs;
if (value != NULL) {
node->value = g_strdup(value);
node->value = str_dup(value);
}
return node;
}
@@ -403,9 +383,9 @@ xml_wr_node_new (const char *name, const char *value, const xml_attr *attrs)
static void
xml_wr_node_free (xml_wr_node *node)
{
g_free((char*) node->name);
g_free((char*) node->value);
g_free(node);
mem_free((char*) node->name);
mem_free((char*) node->value);
mem_free(node);
}
/* Free XML writer node with its children
@@ -426,7 +406,7 @@ xml_wr_node_free_recursive (xml_wr_node *node)
xml_wr*
xml_wr_begin (const char *root, const xml_ns *ns)
{
xml_wr *xml = g_new0(xml_wr, 1);
xml_wr *xml = mem_new(xml_wr, 1);
xml->root = xml_wr_node_new(root, NULL, NULL);
xml->current = xml->root;
xml->ns = ns;
@@ -562,15 +542,13 @@ xml_wr_finish_internal (xml_wr *xml, bool compact)
buf = xml_wr_format_node(xml, buf, xml->root, 0, compact);
xml_wr_node_free_recursive(xml->root);
g_free(xml);
mem_free(xml);
char *s = strdup(buf); // FIXME
mem_free(buf);
return s;
return buf;
}
/* Finish writing, generate document string.
* Caller must g_free() this string after use
* Caller must mem_free() this string after use
*/
char*
xml_wr_finish (xml_wr *xml)
+33 -33
View File
@@ -115,12 +115,12 @@ zeroconf_method_name (ZEROCONF_METHOD method)
static zeroconf_device*
zeroconf_device_add (zeroconf_finding *finding)
{
zeroconf_device *device = g_new0(zeroconf_device, 1);
zeroconf_device *device = mem_new(zeroconf_device, 1);
device->devid = devid_alloc();
device->uuid = finding->uuid;
if (finding->name != NULL) {
device->name = g_strdup(finding->name);
device->name = str_dup(finding->name);
}
device->ifaces = mem_new(int, 0);
@@ -137,9 +137,9 @@ zeroconf_device_del (zeroconf_device *device)
{
mem_free(device->ifaces);
ll_del(&device->node_list);
g_free((char*) device->name);
mem_free((char*) device->name);
devid_free(device->devid);
g_free(device);
mem_free(device);
}
/* Find zeroconf_device by uuid and name
@@ -523,12 +523,12 @@ zeroconf_ident_proto_decode (char c)
}
/* Make device ident string
* The returned string must be released with g_free()
* The returned string must be released with mem_free()
*/
static const char*
zeroconf_ident_make (const char *name, unsigned int devid, ID_PROTO proto)
{
return g_strdup_printf("%c%x:%s", zeroconf_ident_proto_encode(proto),
return str_printf("%c%x:%s", zeroconf_ident_proto_encode(proto),
devid, name);
}
@@ -572,7 +572,7 @@ zeroconf_ident_split (const char *ident, unsigned int *devid, ID_PROTO *proto)
zeroconf_endpoint*
zeroconf_endpoint_new (ID_PROTO proto, http_uri *uri)
{
zeroconf_endpoint *endpoint = g_new0(zeroconf_endpoint, 1);
zeroconf_endpoint *endpoint = mem_new(zeroconf_endpoint, 1);
endpoint->proto = proto;
endpoint->uri = uri;
@@ -589,7 +589,7 @@ zeroconf_endpoint_new (ID_PROTO proto, http_uri *uri)
static zeroconf_endpoint*
zeroconf_endpoint_copy_single (const zeroconf_endpoint *endpoint)
{
zeroconf_endpoint *endpoint2 = g_new0(zeroconf_endpoint, 1);
zeroconf_endpoint *endpoint2 = mem_new(zeroconf_endpoint, 1);
*endpoint2 = *endpoint;
endpoint2->uri = http_uri_clone(endpoint->uri);
@@ -604,7 +604,7 @@ static void
zeroconf_endpoint_free_single (zeroconf_endpoint *endpoint)
{
http_uri_free(endpoint->uri);
g_free(endpoint);
mem_free(endpoint);
}
/* Create a copy of zeroconf_endpoint list
@@ -870,7 +870,7 @@ zeroconf_finding_publish (zeroconf_finding *finding)
/* Case 2: all findings belongs to the same network
* interface; upgrade anonymous device to named
*/
device->name = g_strdup(finding->name);
device->name = str_dup(finding->name);
found_by = "found by uuid";
} else {
/* Case 3: borrow findings that belongs to the new finding's
@@ -1139,7 +1139,7 @@ zeroconf_device_list_get (void)
continue;
}
info = g_new0(SANE_Device, 1);
info = mem_new(SANE_Device, 1);
proto = id_proto_name(dev_conf->proto);
dev_list = sane_device_array_append(dev_list, info);
@@ -1147,9 +1147,9 @@ zeroconf_device_list_get (void)
info->name = zeroconf_ident_make(dev_conf->name, dev_conf->devid,
dev_conf->proto);
info->vendor = g_strdup(proto);
info->model = g_strdup(dev_conf->name);
info->type = g_strdup_printf("%s network scanner", proto);
info->vendor = str_dup(proto);
info->model = str_dup(dev_conf->name);
info->type = str_printf("%s network scanner", proto);
}
dev_count_static = dev_count;
@@ -1181,16 +1181,16 @@ zeroconf_device_list_get (void)
for (proto = 0; proto < NUM_ID_PROTO; proto ++) {
if ((protocols & (1 << proto)) != 0) {
SANE_Device *info = g_new0(SANE_Device, 1);
SANE_Device *info = mem_new(SANE_Device, 1);
const char *proto_name = id_proto_name(proto);
dev_list = sane_device_array_append(dev_list, info);
dev_count ++;
info->name = zeroconf_ident_make(name, device->devid, proto);
info->vendor = g_strdup(proto_name);
info->model = g_strdup(conf.model_is_netname ? name : model);
info->type = g_strdup_printf("%s network scanner", proto_name);
info->vendor = str_dup(proto_name);
info->model = str_dup(conf.model_is_netname ? name : model);
info->type = str_printf("%s network scanner", proto_name);
}
}
}
@@ -1217,11 +1217,11 @@ zeroconf_device_list_free (const SANE_Device **dev_list)
const SANE_Device *info;
for (i = 0; (info = dev_list[i]) != NULL; i ++) {
g_free((void*) info->name);
g_free((void*) info->vendor);
g_free((void*) info->model);
g_free((void*) info->type);
g_free((void*) info);
mem_free((void*) info->name);
mem_free((void*) info->vendor);
mem_free((void*) info->model);
mem_free((void*) info->type);
mem_free((void*) info);
}
sane_device_array_free(dev_list);
@@ -1284,9 +1284,9 @@ zeroconf_parse_devinfo_from_ident(const char *ident)
}
/* Build a zeroconf_devinfo */
devinfo = g_new0(zeroconf_devinfo, 1);
devinfo->ident = g_strdup(ident);
devinfo->name = g_strdup(name);
devinfo = mem_new(zeroconf_devinfo, 1);
devinfo->ident = str_dup(ident);
devinfo->name = str_dup(name);
devinfo->endpoints = zeroconf_endpoint_new(proto, uri);
return devinfo;
}
@@ -1326,18 +1326,18 @@ zeroconf_devinfo_lookup (const char *ident)
}
/* Build a zeroconf_devinfo */
devinfo = g_new0(zeroconf_devinfo, 1);
devinfo->ident = g_strdup(ident);
devinfo = mem_new(zeroconf_devinfo, 1);
devinfo->ident = str_dup(ident);
if (dev_conf != NULL) {
http_uri *uri = http_uri_clone(dev_conf->uri);
devinfo->name = g_strdup(dev_conf->name);
devinfo->name = str_dup(dev_conf->name);
devinfo->endpoints = zeroconf_endpoint_new(dev_conf->proto, uri);
} else {
const char *name, *model;
zeroconf_device_name_model(device, &name, &model);
devinfo->name = g_strdup(name);
devinfo->name = str_dup(name);
devinfo->endpoints = zeroconf_device_endpoints(device, proto);
}
@@ -1350,10 +1350,10 @@ zeroconf_devinfo_lookup (const char *ident)
void
zeroconf_devinfo_free (zeroconf_devinfo *devinfo)
{
g_free((char*) devinfo->ident);
g_free((char*) devinfo->name);
mem_free((char*) devinfo->ident);
mem_free((char*) devinfo->name);
zeroconf_endpoint_list_free(devinfo->endpoints);
g_free(devinfo);
mem_free(devinfo);
}
/******************** Initialization and cleanup *********************/
+23
View File
@@ -292,11 +292,13 @@ void
mem_free (void *p);
/* Get memory block length/capacity, in bytes
* For NULL pointer return 0
*/
size_t mem_len_bytes (const void *p);
size_t mem_cap_bytes (const void *p);
/* Get memory block length/capacity, in elements
* For NULL pointer return 0
*/
#define mem_len(v) (mem_len_bytes(v) / sizeof(*v))
#define mem_cap(v) (mem_cap_bytes(v) / sizeof(*v))
@@ -333,6 +335,21 @@ str_dup (const char *s1)
return s;
}
/* Create new string as a lowercase copy of existent string
*/
char*
str_dup_tolower (const char *s1);
/* Create new string and print to it
*/
char*
str_printf (const char *format, ...);
/* Create new string and print to it, va_list version
*/
char*
str_vprintf (const char *format, va_list ap);
/* Truncate the string
*/
static inline void
@@ -405,6 +422,11 @@ str_append_c (char *s, char c)
char*
str_append_printf (char *s, const char *format, ...);
/* Append formatted string to string -- va_list version
*/
char*
str_append_vprintf (char *s, const char *format, va_list ap);
/* Assign value to string
*
* `s1' must be previously created by some of str_XXX functions,
@@ -540,6 +562,7 @@ __ptr_array_del (void **a, int i)
#define safe_isspace(c) isspace((unsigned char) c)
#define safe_isxdigit(c) isxdigit((unsigned char) c)
#define safe_toupper(c) toupper((unsigned char) c)
#define safe_tolower(c) tolower((unsigned char) c)
/******************** OS Facilities ********************/
/* Get user's home directory. There is no need to
+7 -7
View File
@@ -65,10 +65,10 @@ png_error_fn (png_struct *png_ptr, const char *message)
save_file*
save_open (const char *name, const SANE_Parameters *params)
{
save_file *save = g_new0(save_file, 1);
save_file *save = mem_new(save_file, 1);
int color_type;
save->name = g_strdup(name);
save->name = str_dup(name);
save->fp = fopen(name, "wb");
if (save->fp == NULL) {
die("%s: %s", name, strerror(errno));
@@ -114,8 +114,8 @@ save_close (save_file *save)
png_write_end(save->png_ptr, NULL);
png_destroy_write_struct(&save->png_ptr, &save->info_ptr);
fclose(save->fp);
g_free((char*) save->name);
g_free(save);
mem_free((char*) save->name);
mem_free(save);
}
/* Write a row of image data
@@ -185,7 +185,7 @@ main (int argc, char **argv)
die("%s: %s", file, strerror(errno));
}
data = g_malloc(size);
data = mem_new(char, size);
if ((size_t) size != fread(data, 1, size, fp)) {
die("%s: read error", file);
}
@@ -208,7 +208,7 @@ main (int argc, char **argv)
save = save_open("decoded.png", &params);
line = g_malloc(params.bytes_per_line);
line = mem_new(char, params.bytes_per_line);
for (i = 0; i < params.lines; i ++) {
err = image_decoder_read_line(decoder, line);
if (err != NULL) {
@@ -218,7 +218,7 @@ main (int argc, char **argv)
save_write(save, line);
}
g_free(line);
mem_free(line);
save_close(save);
return 0;