[Geany-Devel] [geany/geany-plugins] 4cc119: Scope: Fix mismatched allocator/deallocator
Matthew Brush
mbrush at xxxxx
Thu Mar 7 19:37:50 UTC 2013
On 13-03-07 11:06 AM, Dimitar Zhekov wrote:
> On Mon, 04 Mar 2013 22:30:40 -0000
> Colomban Wendling <git-noreply at geany.org> wrote:
>
>> Log Message:
>> -----------
>> Scope: Fix mismatched allocator/deallocator
>
> These are not mismatched, I'm using strdup() instead of strdup() for
> strings that must never be NULL. Unless we have a policy to always
> use g_strdup(), or there is a real g_/strdup vs. g_/free mismatch
> somewhere, I'm going to revert them.
>
I don't see any mismatch either but strdup() is not in C standard (at
least C89/99) but rather POSIX or some other one AFAIK.
If you really don't like the g_strdup() behaviour, you could always
write something like:
char* scope_strdup(const char *s)
{
char *n;
size_t len;
if (s == NULL)
g_error("NULL string passed to scope_strdup()");
len = strlen(s) + 1;
n = malloc(len);
memcpy(n, s, len);
return n;
}
Then at least there's some hint of what went wrong rather than just
bringing down the entire program with a mysterious segfault (assuming
the above code I didn't test doesn't do that itself :).
> Personally I prefer offensive programming: if something goes wrong, let
> it crash and burn, get a proper backtrace and fix it.
>
Note to self: don't use Scope plugin until all files are saved :)
Cheers,
Matthew Brush
More information about the Devel
mailing list