On 02/19/2013 12:08 AM, Zach Brown wrote:
> On Mon, Feb 18, 2013 at 10:04:26PM +0100, Goffredo Baroncelli wrote:
>> This patch adds some helpers to manage the strings allocation and
>> deallocation.
>> The function string_list_add(char *) adds the passed string to a list;
>> the function string_list_free() frees all the strings together.
> 
> Please don't do this.  To verify that a given pointer isn't freed before
> it's used we'd have to make sure that there are no string_list_free()
> calls in the interim that would hit their pointer on this global list.

The idea is that the code shouldn't care about do deallocate the strings
until finishing its jobs. At the end it calls string_list_free().

Of course, if after string_list_free() some dynamically allocated
strings are used then bad things could happen.

Ideally string_list_free() should be called at the end of the main.
I don't think that btrfs-progs allocates an huge quantity of string, so
this could be an acceptable behaviour.

> 
> As far as I can tell, this is only used for the pretty units?  Instead
> of
>       printf("%s", leaked_string(raw));
> 
> how about
> 
>       printf("%llu%s", scaled_value(raw), static_unit_str(raw));
> 
> That'd avoid the need to pass back arbitrary allocated strings and this
> code could go away.

Sorry I don't understand the differences between {leaked, scaled,
raw}_string. Could you elaborate a bit ?

> 
>> +    if (!strings_to_free) {
>> +            fprintf(stderr, "add_string_to_free(): Not enough memory\n");
>> +            strings_to_free = 0;
> 
> if (a == 0) a = 0?
> 
>> +            count_string_to_free = 0;
>> +    }
>> +
>> +    strings_to_free[count_string_to_free-1] = s;
> 
> NULL[-1] = s?

Right, I will correct soon.

> 
> - z
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


-- 
gpg @keyserver.linux.it: Goffredo Baroncelli (kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to