mirror of
https://gitee.com/openharmony/third_party_libnl
synced 2025-02-25 22:07:13 +00:00
lib/data.c: avoid memleak if realloc fails
This commit is contained in:
parent
77a4c150bb
commit
8d807b215f
@ -111,15 +111,16 @@ struct nl_data *nl_data_clone(const struct nl_data *src)
|
||||
int nl_data_append(struct nl_data *data, const void *buf, size_t size)
|
||||
{
|
||||
if (size > 0) {
|
||||
data->d_data = realloc(data->d_data, data->d_size + size);
|
||||
if (!data->d_data)
|
||||
void *d_data = realloc(data->d_data, data->d_size + size);
|
||||
if (!d_data)
|
||||
return -NLE_NOMEM;
|
||||
|
||||
if (buf)
|
||||
memcpy(data->d_data + data->d_size, buf, size);
|
||||
memcpy(d_data + data->d_size, buf, size);
|
||||
else
|
||||
memset(data->d_data + data->d_size, 0, size);
|
||||
memset(d_data + data->d_size, 0, size);
|
||||
|
||||
data->d_data = d_data;
|
||||
data->d_size += size;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user