[LEDE-DEV] [PATCH libubox 1/3] Fix various memory management issues

Matthias Schiffer mschiffer at universe-factory.net
Tue Jun 21 03:43:26 PDT 2016


On 06/21/2016 12:32 PM, Jo-Philipp Wich wrote:
> Hi,
> 
> first of all, thanks for putting work into that - I like the changes in
> general. Have a few comments inline below.
> 
> ~ Jo
> 
>> Consistently handle allocation failures. Some functions are changed to
>> return bool instead of void to allow returning an error.
>>
>> Also fix a buffer size miscalculation in lua/uloop.
>>
>> Signed-off-by: Matthias Schiffer <mschiffer at universe-factory.net>
>> ---
[...]
>> @@ -316,8 +323,13 @@ char *blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, blobmsg_jso
>>  		return NULL;
>>  	}
>>  
>> -	s.buf = realloc(s.buf, s.pos + 1);
>> -	s.buf[s.pos] = 0;
>> +	ret = realloc(s.buf, s.pos + 1);
>> +	if (!ret) {
>> +		free(s.buf);
>> +		return NULL;
>> +	}
>>  
>> -	return s.buf;
>> +	ret[s.pos] = 0;
> 
> Did you forget to assign "ret" to "s.buf" here?
This one is correct as is, s is a local variable, so assigning it at the
end doesn't make sense.

> 
>> +
>> +	return ret;
>>  }
[...]

Thanks for having a look, I'll fix up the rest.

Matthias



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20160621/849c1311/attachment.sig>


More information about the Lede-dev mailing list