在 2017年10月19日 16:00, Hiltjo Posthuma 写道: > On Thu, Oct 19, 2017 at 12:47:41PM +0800, 黄建忠 wrote: >> When using ctrl-p to load uri from clipboard, it's better to strip the >> leading whitespace. >> >> For example, to select/copy a uri from text in terminal and paste to >> surf, currently it need to be very careful not to include any whitespace >> before the uri. >> >> It's easy for keyboard selection, but for mouse selection, precise >> positioning is a little bit difficult. >> >> >> patch as below: >> >> diff -Nur surf/surf.c surfn/surf.c >> --- surf/surf.c 2017-10-17 13:58:00.636699137 +0800 >> +++ surfn/surf.c 2017-10-17 13:58:29.440798516 +0800 >> @@ -1707,7 +1707,8 @@ >> void >> pasteuri(GtkClipboard *clipboard, const char *text, gpointer d) >> { >> - Arg a = {.v = text }; >> + char *trimed = g_strstrip(g_strdup(text)); >> + Arg a = {.v = trimed }; >> if (text) >> loaduri((Client *) d, &a); >> } >> >> >> -- >> Huang JianZhong >> >> > Hey, > > Doesn't this leak memory? > > (NOTE: for single-use programs it is ok to not free memory at the end). > Tks, g_strdup need g_free, g_strstrip will not allocate new memory.
Maybe it should changed like this? if (text) { char *atext = g_strdup(text); char *trimed = g_strstrip(atext); Arg a = {.v = trimed }; loaduri((Client *) d, &a); g_free(atext); } -- Huang JianZhong