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

Re: xdebug: FTBFS on hurd-i386 (for review)



On Tue, 2014-04-15 at 14:21 +0200, Samuel Thibault wrote:
> Svante Signell, le Tue 15 Apr 2014 14:18:44 +0200, a écrit :
> > On Tue, 2014-04-15 at 13:29 +0200, Samuel Thibault wrote:
> > > Svante Signell, le Tue 15 Apr 2014 12:07:22 +0200, a écrit :
> > > > > Will obviously crash. Did you try your code at all?
> > > > 
> > > > I wrote a test program and run that one through valgind. Better now?
> > > 
> > > Did you really make your program go through your patched code?
> > > 
> > > > +	dfp = xdstrdup(efp);
> > > 
> > > That doesn't get free in the if branch.

Well, freeing tmp instead of dfp in my test program *_old.c gave zero
errors in valgrind (as well as the modified program, both attached)

> > How to do that properly then?
> 
> Just like the original source code for instance: keep the allocated
> pointer in dfp, and use fp for browsing it.

Please explain why the _old example escaped problems with valgrind?
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

 char *xdebug_path_from_url(const char *fileurl)
 {
   char *dfp = NULL, *tmp = NULL, *ret = NULL;;
   const char *fp, *efp = fileurl;

   dfp = strdup(efp);
   fp = dfp;
   tmp = strstr(fp, "file://");

   if (tmp) {
     fp = tmp + 7;
     if (fp[0] == '/' && fp[2] == ':') {
       fp++;
     }
     ret = strdup(fp);
   } else {
     ret = strdup(fileurl);
   }

   free(dfp);
   return ret;
 }

int main(void)
{
  char *fileurl = "file://this_is_a_test";
  //char *fileurl = "/this_is_a_test";

  char *filename = xdebug_path_from_url(fileurl);
  printf("fileurl = %s\n", fileurl);
  printf("filename = %s\n", filename);
  free(filename);

  return 0;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

 char *xdebug_path_from_url(const char *fileurl)
 {
   const char *efp = fileurl;
   char *dfp = NULL, *tmp = NULL, *ret = NULL;;

   dfp = strdup(efp);
   tmp = strstr(dfp, "file://");

   if (tmp) {
     dfp = tmp + 7;
     if (dfp[0] == '/' && dfp[2] == ':') {
       dfp++;
     }
     ret = strdup(dfp);
     /* FIXME */
     free(tmp);
   } else {
     ret = strdup(fileurl);
     free(dfp);
   }
   return ret;
 }

int main(void)
{
  char *fileurl = "file://this_is_a_test";
  //char *fileurl = "/this_is_a_test";

  char *filename = xdebug_path_from_url(fileurl);
  printf("fileurl = %s\n", fileurl);
  printf("filename = %s\n", filename);
  free(filename);

  return 0;
}

Reply to: