X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibsystemd%2Fsd-rtnl%2Fsd-rtnl.c;h=8e709bb66dfb16c3a9c73a7bf47af178b1e9006a;hb=77768cbabc97d27535bd5329a11490f5c35a63f3;hp=9f3a4f3deaf759797f888798d57ccff66909317a;hpb=8c57830308a612b06b53f5fd31cfb765d8710d68;p=elogind.git diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c index 9f3a4f3de..8e709bb66 100644 --- a/src/libsystemd/sd-rtnl/sd-rtnl.c +++ b/src/libsystemd/sd-rtnl/sd-rtnl.c @@ -31,7 +31,7 @@ #include "rtnl-util.h" static int sd_rtnl_new(sd_rtnl **ret) { - sd_rtnl *rtnl; + _cleanup_rtnl_unref_ sd_rtnl *rtnl = NULL; assert_return(ret, -EINVAL); @@ -51,13 +51,12 @@ static int sd_rtnl_new(sd_rtnl **ret) { /* We guarantee that wqueue always has space for at least * one entry */ - rtnl->wqueue = new(sd_rtnl_message*, 1); - if (!rtnl->wqueue) { - free(rtnl); + if (!GREEDY_REALLOC(rtnl->wqueue, rtnl->wqueue_allocated, 1)) return -ENOMEM; - } *ret = rtnl; + rtnl = NULL; + return 0; } @@ -188,18 +187,14 @@ int sd_rtnl_send(sd_rtnl *nl, nl->wqueue_size = 1; } } else { - sd_rtnl_message **q; - /* append to queue */ if (nl->wqueue_size >= RTNL_WQUEUE_MAX) return -ENOBUFS; - q = realloc(nl->wqueue, sizeof(sd_rtnl_message*) * (nl->wqueue_size + 1)); - if (!q) + if (!GREEDY_REALLOC(nl->wqueue, nl->wqueue_allocated, nl->wqueue_size + 1)) return -ENOMEM; - nl->wqueue = q; - q[nl->wqueue_size ++] = sd_rtnl_message_ref(message); + nl->wqueue[nl->wqueue_size ++] = sd_rtnl_message_ref(message); } if (serial)