[Mesa-dev] [PATCH 4/7] util: Port nir_array functionality to u_dynarray
Kenneth Graunke
kenneth at whitecape.org
Mon Jun 12 01:06:06 UTC 2017
On Saturday, June 3, 2017 11:11:39 AM PDT Thomas Helland wrote:
[snip]
> @@ -87,10 +102,18 @@ util_dynarray_trim(struct util_dynarray *buf)
> {
> if (buf->size != buf->capacity) {
> if (buf->size) {
> - buf->data = realloc(buf->data, buf->size);
> + if (buf->mem_ctx) {
> + reralloc_size(buf->mem_ctx, buf->data, buf->size);
> + } else {
> + buf->data = realloc(buf->data, buf->size);
> + }
Hi Thomas,
Would it make sense to do:
buf->data = reralloc_size(...)
It's probably safe as is given that you're trying to trim down an
existing allocation to be smaller, but it seems safer to use the return
value nonetheless. Coverity grumbled after you pushed the patch:
** CID 1412568: Resource leaks (RESOURCE_LEAK)
/src/util/u_dynarray.h: 110 in util_dynarray_trim()
______________________________________________________________
*** CID 1412568: Resource leaks (RESOURCE_LEAK)
/src/util/u_dynarray.h: 110 in util_dynarray_trim()
104 static inline void
105 util_dynarray_trim(struct util_dynarray *buf)
106 {
107 if (buf->size != buf->capacity) {
108 if (buf->size) {
109 if (buf->mem_ctx) {
>>> CID 1412568: Resource leaks (RESOURCE_LEAK)
>>> Ignoring storage allocated by "reralloc_size(buf->mem_ctx, buf->data, buf->size)" leaks it.
110 reralloc_size(buf->mem_ctx, buf->data, buf->size);
111 } else {
112 buf->data = realloc(buf->data, buf->size);
113 }
114 buf->capacity = buf->size;
115 } else {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170611/054d74f9/attachment-0001.sig>
More information about the mesa-dev
mailing list