Re: g_strstrip question.



  If so, how do I free the whole string so that I do not get memory leaks ?

        If you have some string str1 which you need to free...

        char *str1;
        char *oldstr;

        /* Replace this with however str1 is allocated */
        str1 = g_strdup("Some random string");
        
        /* Save a copy */
        oldstr = str1;
        
        str1 = g_strstrip(str1);
        ...

        g_free(oldstr); /* str1 is now an invalid pointer */
        str1 = oldstr = NULL; /* sanity */
        
        Regards,
        nash

-- 
Brett Nash <nash nash nu>
Sometimes it's better to light a flamethrower than curse the darkness.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]