You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Eric Gillespie <ep...@pretzelnet.org> on 2008/05/09 01:05:57 UTC

ra-serf bug

It's been a long time since I made the vague claim "serf breaks
the Python binding"; today I finally decided to try to narrow it
down.  I have a tiny little C program that demonstrates the problem:

0 svn% ./serfbug svn://svn/r 84
fetched 118171
# neon
0 svn% ./serfbug https://svn/r 84
fetched 118171
# serf
0 svn% ./serfbug https://svn/r 84
subversion/libsvn_ra_serf/util.c:551: (apr_err=20014)
foo: Error running context: Internal error
*** glibc detected *** double free or corruption (!prev):
0x08098f68 ***
zsh: abort (core dumped)  ./serfbug https://svn/r 84

This happens with both 1.5.x and trunk, fresh as of 5 minutes ago
(r31106).  The error (but not the double free) goes away if you
pass revision instead of SVN_INVALID_REVNUM.


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

/* for svn initialization */
#include <apr_errno.h>
#include <apr_general.h>
#include <apr_strings.h>
#include <svn_auth.h>
#include <svn_cmdline.h>
#include <svn_config.h>
#include <svn_dso.h>
#include <svn_nls.h>
#include <svn_pools.h>
/* for svn_ra_get_dir2 */
#include <apr_hash.h>
#include <svn_error.h>
#include <svn_io.h>
#include <svn_path.h>
#include <svn_ra.h>

static svn_error_t *
open_tmp_file(apr_file_t **fp, void *baton, apr_pool_t *pool)
{
  const char *base_fn, *base_path, *fn;
  SVN_ERR(svn_io_temp_dir(&base_fn, pool));
  base_path = svn_path_join(base_fn, "foo", pool);
  return svn_io_open_unique_file2(fp, &fn, base_path, ".tmp",
                                  svn_io_file_del_on_close, pool);
}

#define ERR(expr)                                               \
  do {                                                          \
    svn_error_t *err = (expr);                                  \
    if (err) {                                                  \
      fprintf(stderr, "%s:%ld: (apr_err=%d)\nfoo: %s\n",         \
              err->file, err->line, err->apr_err,               \
              err->message);                                    \
      return 1;                                                 \
    }                                                           \
  } while (0)

int
main(int argc, char *argv[])
{
  apr_pool_t *pool;
  apr_hash_t *cfg_hash;
  long revision;
  svn_ra_callbacks2_t *callbacks;

  if (argc < 3 || (argv[1] && argv[1][0] == '-')) {
    fputs("usage: foo URL REVISION\n", stderr);
    if (argv[1] && argv[1][0] == '-') {
      return 0;
    }
    return 2;
  }

  errno = 0;
  revision = strtol(argv[2], NULL, 10);
  if (errno != 0) {
    fprintf(stderr, "foo: strtol(%s): ", argv[2]);
    perror("");
    return 3;
  }

  /* Initialize svn. */
  {
    apr_status_t apr_status;
    char buf[1024];

    if ((apr_status = apr_initialize()) != APR_SUCCESS) {
      apr_strerror(apr_status, buf, sizeof(buf) - 1);
      fprintf(stderr, "foo: cannot initialize APR: %s\n", buf);
      return 1;
    }

    svn_dso_initialize();

    if (atexit(apr_terminate) != 0) {
      fputs("atexit registration failed\n", stderr);
      return 1;
    }

    pool = svn_pool_create(NULL);
    svn_utf_initialize(pool);
    ERR(svn_nls_init());

    ERR(svn_config_get_config(&cfg_hash, NULL, pool));

    ERR(svn_ra_initialize(pool));

    ERR(svn_ra_create_callbacks(&callbacks, pool));
    callbacks->open_tmp_file = open_tmp_file;
    ERR(svn_cmdline_setup_auth_baton(&(callbacks->auth_baton),
                                     TRUE,  /* non_interactive */
                                     NULL,  /* username */
                                     NULL,  /* password */
                                     NULL,  /* config_dir */
                                     FALSE, /* no_auth_cache */
                                     apr_hash_get(cfg_hash,
                                                  SVN_CONFIG_CATEGORY_CONFIG,
                                                  APR_HASH_KEY_STRING),
                                     NULL,  /* cancel_func */
                                     NULL,  /* cancel_baton */
                                     pool));
  }

  /* Try something simple enough. */
  {
    svn_ra_session_t *ra;
    apr_hash_t *dirents;
    svn_revnum_t fetched_rev;
    apr_hash_t *props;
    ERR(svn_ra_open2(&ra, argv[1], callbacks, NULL, cfg_hash, pool));
    ERR(svn_ra_get_dir2(ra, &dirents, &fetched_rev, &props,
                        "",                 /* path */
                        SVN_INVALID_REVNUM, /* revision */
                        0,                  /* dirent_fields */
                        pool));
    printf("fetched %ld\n", fetched_rev);
  }

  return 0;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
On Thu, May 8, 2008 at 6:05 PM, Eric Gillespie <ep...@pretzelnet.org> wrote:
> It's been a long time since I made the vague claim "serf breaks
>  the Python binding"; today I finally decided to try to narrow it
>  down.  I have a tiny little C program that demonstrates the problem:

Thanks for the repro.  r31107 has the fix.  -- justin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Eric Gillespie <ep...@pretzelnet.org>.
Lieven Govaerts <sv...@mobsol.be> writes:

> Can you check if r31234 fixes your last two problems?

All 3 problems are fixed now, thanks.  The next problem is not so
simple to reproduce, though, so I'm just going to abandon serf
again.  I think what I'm seeing is related to
http://subversion.tigris.org/issues/show_bug.cgi?id=2939

Thanks.

-- 
Eric Gillespie <*> epg@pretzelnet.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Lieven Govaerts <sv...@mobsol.be>.
Eric Gillespie wrote:
> Lieven Govaerts <sv...@mobsol.be> writes:
> 
>> Attached is a second and better version of the patch. The 404 is now 
>> converted to an error deeper in ra_serf code, which made svn with last 
>> patch bail out while finding out the vcc/relative urls.
> 
> OK, this fixes that problem, +1 to commit.
> 
> Next problem:
> 
> svn_ra_check_path is supposed to set kind to svn_node_none if path does
> not exist, but ra-serf raises SVN_ERR_RA_DAV_PATH_NOT_FOUND instead.
> 
It looks like it's previous patch that introduces this issue. It's the 
one place related to property handling where a 404 is handled, and since 
the patch converts a 404 now to an error that error is raised before the 
node kind can be set to svn_node_none.

Can you check if r31234 fixes your last two problems?

Lieven

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Eric Gillespie <ep...@pretzelnet.org>.
Lieven Govaerts <sv...@mobsol.be> writes:

> Attached is a second and better version of the patch. The 404 is now 
> converted to an error deeper in ra_serf code, which made svn with last 
> patch bail out while finding out the vcc/relative urls.

OK, this fixes that problem, +1 to commit.

Next problem:

svn_ra_check_path is supposed to set kind to svn_node_none if path does
not exist, but ra-serf raises SVN_ERR_RA_DAV_PATH_NOT_FOUND instead.

Demonstration:


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

/* for svn initialization */
#include <apr_errno.h>
#include <apr_general.h>
#include <apr_hash.h>
#include <apr_strings.h>
#include <svn_auth.h>
#include <svn_cmdline.h>
#include <svn_config.h>
#include <svn_dso.h>
#include <svn_nls.h>
#include <svn_pools.h>
/* for open_tmp_file */
#include <svn_io.h>
#include <svn_path.h>
/* for svn_ra_get_dir2 */
#include <svn_error.h>
#include <svn_ra.h>
#include <svn_types.h>

static svn_error_t *
open_tmp_file(apr_file_t **fp, void *baton, apr_pool_t *pool)
{
  const char *base_fn, *base_path, *fn;
  SVN_ERR(svn_io_temp_dir(&base_fn, pool));
  base_path = svn_path_join(base_fn, "foo", pool);
  return svn_io_open_unique_file2(fp, &fn, base_path, ".tmp",
                                  svn_io_file_del_on_close, pool);
}

#define ERR(expr)                                               \
  do {                                                          \
    svn_error_t *err = (expr);                                  \
    if (err) {                                                  \
      fprintf(stderr, "%s:%ld: (apr_err=%d)\nfoo: %s\n",         \
              err->file, err->line, err->apr_err,               \
              err->message);                                    \
      return 1;                                                 \
    }                                                           \
  } while (0)

int
main(int argc, char *argv[])
{
  apr_pool_t *pool;
  apr_hash_t *cfg_hash;
  long revision;
  svn_ra_callbacks2_t *callbacks;

  if (argc < 3 || (argv[1] && argv[1][0] == '-')) {
    fputs("usage: foo URL REVISION\n", stderr);
    if (argv[1] && argv[1][0] == '-') {
      return 0;
    }
    return 2;
  }

  errno = 0;
  revision = strtol(argv[2], NULL, 10);
  if (errno != 0) {
    fprintf(stderr, "foo: strtol(%s): ", argv[2]);
    perror("");
    return 3;
  }

  /* Initialize svn. */
  {
    apr_status_t apr_status;
    char buf[1024];

    if ((apr_status = apr_initialize()) != APR_SUCCESS) {
      apr_strerror(apr_status, buf, sizeof(buf) - 1);
      fprintf(stderr, "foo: cannot initialize APR: %s\n", buf);
      return 1;
    }

    svn_dso_initialize();

    if (atexit(apr_terminate) != 0) {
      fputs("atexit registration failed\n", stderr);
      return 1;
    }

    pool = svn_pool_create(NULL);
    svn_utf_initialize(pool);
    ERR(svn_nls_init());

    ERR(svn_config_get_config(&cfg_hash, NULL, pool));

    ERR(svn_ra_initialize(pool));

    ERR(svn_ra_create_callbacks(&callbacks, pool));
    callbacks->open_tmp_file = open_tmp_file;
    ERR(svn_cmdline_setup_auth_baton(&(callbacks->auth_baton),
                                     TRUE,  /* non_interactive */
                                     NULL,  /* username */
                                     NULL,  /* password */
                                     NULL,  /* config_dir */
                                     FALSE, /* no_auth_cache */
                                     apr_hash_get(cfg_hash,
                                                  SVN_CONFIG_CATEGORY_CONFIG,
                                                  APR_HASH_KEY_STRING),
                                     NULL,  /* cancel_func */
                                     NULL,  /* cancel_baton */
                                     pool));
  }

  {
    svn_ra_session_t *ra;
    svn_revnum_t head;
    svn_node_kind_t kind;
    ERR(svn_ra_open2(&ra, argv[1], callbacks, NULL, cfg_hash, pool));
    ERR(svn_ra_get_latest_revnum(ra, &head, pool));

    /* Try something simple enough. */
    ERR(svn_ra_check_path(ra, "notexist", head, &kind, pool));
    if (kind == svn_node_none)
      puts("good, kind is none");
    else
      printf("bad, kind is %d\n", kind);
  }

  return 0;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Lieven Govaerts <sv...@mobsol.be>.
Eric Gillespie wrote:
> ping :)
> 
> Eric Gillespie <ep...@pretzelnet.org> writes:
> 
>> Lieven Govaerts <sv...@mobsol.be> writes:
>>
>>> Index: subversion/libsvn_ra_serf/property.c
>>> ===================================================================
>>> --- subversion/libsvn_ra_serf/property.c	(revision 31082)
>>> +++ subversion/libsvn_ra_serf/property.c	(working copy)
>>> @@ -612,6 +612,13 @@ svn_ra_serf__wait_for_props(svn_ra_serf__propfind_
>>>        svn_error_clear(err);
>>>        SVN_ERR(prop_ctx->parser_ctx->error);
>>>      }
>>> +  if (prop_ctx->parser_ctx->status_code == 404)
>> Looks like status_code is a pointer to the status code, so you
>> need to dereference it.

Right.

>>  Even then, I still get the bogus dirent rather than NULL.
> 
Attached is a second and better version of the patch. The 404 is now 
converted to an error deeper in ra_serf code, which made svn with last 
patch bail out while finding out the vcc/relative urls.

There might be other similar situations, so maybe this patch isn't 
complete, but atleast it should solve your specific issue.

Lieven





Re: ra-serf bug

Posted by Eric Gillespie <ep...@pretzelnet.org>.
ping :)

Eric Gillespie <ep...@pretzelnet.org> writes:

> Lieven Govaerts <sv...@mobsol.be> writes:
> 
> > Index: subversion/libsvn_ra_serf/property.c
> > ===================================================================
> > --- subversion/libsvn_ra_serf/property.c	(revision 31082)
> > +++ subversion/libsvn_ra_serf/property.c	(working copy)
> > @@ -612,6 +612,13 @@ svn_ra_serf__wait_for_props(svn_ra_serf__propfind_
> >        svn_error_clear(err);
> >        SVN_ERR(prop_ctx->parser_ctx->error);
> >      }
> > +  if (prop_ctx->parser_ctx->status_code == 404)
> 
> Looks like status_code is a pointer to the status code, so you
> need to dereference it.  Even then, I still get the bogus dirent
> rather than NULL.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Eric Gillespie <ep...@pretzelnet.org>.
Lieven Govaerts <sv...@mobsol.be> writes:

> Index: subversion/libsvn_ra_serf/property.c
> ===================================================================
> --- subversion/libsvn_ra_serf/property.c	(revision 31082)
> +++ subversion/libsvn_ra_serf/property.c	(working copy)
> @@ -612,6 +612,13 @@ svn_ra_serf__wait_for_props(svn_ra_serf__propfind_
>        svn_error_clear(err);
>        SVN_ERR(prop_ctx->parser_ctx->error);
>      }
> +  if (prop_ctx->parser_ctx->status_code == 404)

Looks like status_code is a pointer to the status code, so you
need to dereference it.  Even then, I still get the bogus dirent
rather than NULL.

-- 
Eric Gillespie <*> epg@pretzelnet.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Lieven Govaerts <sv...@mobsol.be>.
Karl Fogel wrote:
> Eric Gillespie <ep...@pretzelnet.org> writes:
>> Got another one for you: svn_ra_stat is supposed to return NULL
>> for the dirent for paths that do not exist; local/svn/neon do,
>> but serf just returns a bogus one:
> 
> Just looking into this briefly between beer and bed (no, really): 
> 
> Would a non-existent path be indicated by a particular value in
> prop_ctx->status_code after svn_ra_serf__wait_for_props() is done?  I'm
> talking about in serf.c:fetch_path_props().  The call to that function
> in svn_ra_serf__stat() seems like the only chance we'd have to discover
> the path does not exist.
> 
The equivalent ra_neon code in svn_ra_neon__do_stat uses a 404 response 
code when fetching the properties to set dirent to NULL.

Attached (untested, no log msg) patch should solve this problem.

Lieven

Re: ra-serf bug

Posted by Karl Fogel <kf...@red-bean.com>.
Eric Gillespie <ep...@pretzelnet.org> writes:
> Got another one for you: svn_ra_stat is supposed to return NULL
> for the dirent for paths that do not exist; local/svn/neon do,
> but serf just returns a bogus one:

Just looking into this briefly between beer and bed (no, really): 

Would a non-existent path be indicated by a particular value in
prop_ctx->status_code after svn_ra_serf__wait_for_props() is done?  I'm
talking about in serf.c:fetch_path_props().  The call to that function
in svn_ra_serf__stat() seems like the only chance we'd have to discover
the path does not exist.

Also, by the by: very few calls to svn_ra_serf__deliver_props() wrap it
in an SVN_ERR() check (though two calls do, oddly enough).  It's just a
style issue right now, as that function in practice only returns
SVN_NO_ERROR anyway, but it does seem like the error checks ought to be
there, in case the function ever gets more sophisticated.

-Karl

> 0 svn% ./serfbug2 svn://svn/r 84
> dirent NULL
> # neon
> 0 svn% ./serfbug2 https://svn/r 84
> dirent NULL
> # serf
> 0 svn% ./serfbug2 https://svn/r 84
> dirent not NULL:
>  kind 0
>  size 0
>  has_props 0
>  created_rev 0
>  time 0
>  last_author (null)
> *** glibc detected *** double free or corruption (!prev):
> 0x08098f18 ***
> zsh: abort (core dumped)  ./serfbug2 https://svn/r 84
>
>
> #include <errno.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> /* for svn initialization */
> #include <apr_errno.h>
> #include <apr_general.h>
> #include <apr_hash.h>
> #include <apr_strings.h>
> #include <svn_auth.h>
> #include <svn_cmdline.h>
> #include <svn_config.h>
> #include <svn_dso.h>
> #include <svn_nls.h>
> #include <svn_pools.h>
> /* for svn_ra_stat */
> #include <svn_error.h>
> #include <svn_io.h>
> #include <svn_path.h>
> #include <svn_ra.h>
> #include <svn_types.h>
>
> static svn_error_t *
> open_tmp_file(apr_file_t **fp, void *baton, apr_pool_t *pool)
> {
>   const char *base_fn, *base_path, *fn;
>   SVN_ERR(svn_io_temp_dir(&base_fn, pool));
>   base_path = svn_path_join(base_fn, "foo", pool);
>   return svn_io_open_unique_file2(fp, &fn, base_path, ".tmp",
>                                   svn_io_file_del_on_close, pool);
> }
>
> #define ERR(expr)                                               \
>   do {                                                          \
>     svn_error_t *err = (expr);                                  \
>     if (err) {                                                  \
>       fprintf(stderr, "%s:%ld: (apr_err=%d)\nfoo: %s\n",         \
>               err->file, err->line, err->apr_err,               \
>               err->message);                                    \
>       return 1;                                                 \
>     }                                                           \
>   } while (0)
>
> int
> main(int argc, char *argv[])
> {
>   apr_pool_t *pool;
>   apr_hash_t *cfg_hash;
>   long revision;
>   svn_ra_callbacks2_t *callbacks;
>
>   if (argc < 3 || (argv[1] && argv[1][0] == '-')) {
>     fputs("usage: foo URL REVISION\n", stderr);
>     if (argv[1] && argv[1][0] == '-') {
>       return 0;
>     }
>     return 2;
>   }
>
>   errno = 0;
>   revision = strtol(argv[2], NULL, 10);
>   if (errno != 0) {
>     fprintf(stderr, "foo: strtol(%s): ", argv[2]);
>     perror("");
>     return 3;
>   }
>
>   /* Initialize svn. */
>   {
>     apr_status_t apr_status;
>     char buf[1024];
>
>     if ((apr_status = apr_initialize()) != APR_SUCCESS) {
>       apr_strerror(apr_status, buf, sizeof(buf) - 1);
>       fprintf(stderr, "foo: cannot initialize APR: %s\n", buf);
>       return 1;
>     }
>
>     svn_dso_initialize();
>
>     if (atexit(apr_terminate) != 0) {
>       fputs("atexit registration failed\n", stderr);
>       return 1;
>     }
>
>     pool = svn_pool_create(NULL);
>     svn_utf_initialize(pool);
>     ERR(svn_nls_init());
>
>     ERR(svn_config_get_config(&cfg_hash, NULL, pool));
>
>     ERR(svn_ra_initialize(pool));
>
>     ERR(svn_ra_create_callbacks(&callbacks, pool));
>     callbacks->open_tmp_file = open_tmp_file;
>     ERR(svn_cmdline_setup_auth_baton(&(callbacks->auth_baton),
>                                      TRUE,  /* non_interactive */
>                                      NULL,  /* username */
>                                      NULL,  /* password */
>                                      NULL,  /* config_dir */
>                                      FALSE, /* no_auth_cache */
>                                      apr_hash_get(cfg_hash,
>                                                   SVN_CONFIG_CATEGORY_CONFIG,
>                                                   APR_HASH_KEY_STRING),
>                                      NULL,  /* cancel_func */
>                                      NULL,  /* cancel_baton */
>                                      pool));
>   }
>
>   /* Try something simple enough. */
>   {
>     svn_ra_session_t *ra;
>     svn_revnum_t head;
>     svn_dirent_t *dirent;
>     ERR(svn_ra_open2(&ra, argv[1], callbacks, NULL, cfg_hash, pool));
>     ERR(svn_ra_get_latest_revnum(ra, &head, pool));
>     ERR(svn_ra_stat(ra, "notexist", head, &dirent, pool));
>     if (dirent == NULL)
>       puts("dirent NULL");
>     else
>       {
>         printf("dirent not NULL:\n"
>                " kind %d\n"
>                " size %lld\n"
>                " has_props %d\n"
>                " created_rev %lld\n"
>                " time %lld\n"
>                " last_author %s\n",
>                dirent->kind, (long long)dirent->size, dirent->has_props,
>                (long long)dirent->created_rev, (long long)dirent->time,
>                dirent->last_author);
>       }
>   }
>
>   return 0;
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: dev-help@subversion.tigris.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Eric Gillespie <ep...@pretzelnet.org>.
Got another one for you: svn_ra_stat is supposed to return NULL
for the dirent for paths that do not exist; local/svn/neon do,
but serf just returns a bogus one:

0 svn% ./serfbug2 svn://svn/r 84
dirent NULL
# neon
0 svn% ./serfbug2 https://svn/r 84
dirent NULL
# serf
0 svn% ./serfbug2 https://svn/r 84
dirent not NULL:
 kind 0
 size 0
 has_props 0
 created_rev 0
 time 0
 last_author (null)
*** glibc detected *** double free or corruption (!prev):
0x08098f18 ***
zsh: abort (core dumped)  ./serfbug2 https://svn/r 84


#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

/* for svn initialization */
#include <apr_errno.h>
#include <apr_general.h>
#include <apr_hash.h>
#include <apr_strings.h>
#include <svn_auth.h>
#include <svn_cmdline.h>
#include <svn_config.h>
#include <svn_dso.h>
#include <svn_nls.h>
#include <svn_pools.h>
/* for svn_ra_stat */
#include <svn_error.h>
#include <svn_io.h>
#include <svn_path.h>
#include <svn_ra.h>
#include <svn_types.h>

static svn_error_t *
open_tmp_file(apr_file_t **fp, void *baton, apr_pool_t *pool)
{
  const char *base_fn, *base_path, *fn;
  SVN_ERR(svn_io_temp_dir(&base_fn, pool));
  base_path = svn_path_join(base_fn, "foo", pool);
  return svn_io_open_unique_file2(fp, &fn, base_path, ".tmp",
                                  svn_io_file_del_on_close, pool);
}

#define ERR(expr)                                               \
  do {                                                          \
    svn_error_t *err = (expr);                                  \
    if (err) {                                                  \
      fprintf(stderr, "%s:%ld: (apr_err=%d)\nfoo: %s\n",         \
              err->file, err->line, err->apr_err,               \
              err->message);                                    \
      return 1;                                                 \
    }                                                           \
  } while (0)

int
main(int argc, char *argv[])
{
  apr_pool_t *pool;
  apr_hash_t *cfg_hash;
  long revision;
  svn_ra_callbacks2_t *callbacks;

  if (argc < 3 || (argv[1] && argv[1][0] == '-')) {
    fputs("usage: foo URL REVISION\n", stderr);
    if (argv[1] && argv[1][0] == '-') {
      return 0;
    }
    return 2;
  }

  errno = 0;
  revision = strtol(argv[2], NULL, 10);
  if (errno != 0) {
    fprintf(stderr, "foo: strtol(%s): ", argv[2]);
    perror("");
    return 3;
  }

  /* Initialize svn. */
  {
    apr_status_t apr_status;
    char buf[1024];

    if ((apr_status = apr_initialize()) != APR_SUCCESS) {
      apr_strerror(apr_status, buf, sizeof(buf) - 1);
      fprintf(stderr, "foo: cannot initialize APR: %s\n", buf);
      return 1;
    }

    svn_dso_initialize();

    if (atexit(apr_terminate) != 0) {
      fputs("atexit registration failed\n", stderr);
      return 1;
    }

    pool = svn_pool_create(NULL);
    svn_utf_initialize(pool);
    ERR(svn_nls_init());

    ERR(svn_config_get_config(&cfg_hash, NULL, pool));

    ERR(svn_ra_initialize(pool));

    ERR(svn_ra_create_callbacks(&callbacks, pool));
    callbacks->open_tmp_file = open_tmp_file;
    ERR(svn_cmdline_setup_auth_baton(&(callbacks->auth_baton),
                                     TRUE,  /* non_interactive */
                                     NULL,  /* username */
                                     NULL,  /* password */
                                     NULL,  /* config_dir */
                                     FALSE, /* no_auth_cache */
                                     apr_hash_get(cfg_hash,
                                                  SVN_CONFIG_CATEGORY_CONFIG,
                                                  APR_HASH_KEY_STRING),
                                     NULL,  /* cancel_func */
                                     NULL,  /* cancel_baton */
                                     pool));
  }

  /* Try something simple enough. */
  {
    svn_ra_session_t *ra;
    svn_revnum_t head;
    svn_dirent_t *dirent;
    ERR(svn_ra_open2(&ra, argv[1], callbacks, NULL, cfg_hash, pool));
    ERR(svn_ra_get_latest_revnum(ra, &head, pool));
    ERR(svn_ra_stat(ra, "notexist", head, &dirent, pool));
    if (dirent == NULL)
      puts("dirent NULL");
    else
      {
        printf("dirent not NULL:\n"
               " kind %d\n"
               " size %lld\n"
               " has_props %d\n"
               " created_rev %lld\n"
               " time %lld\n"
               " last_author %s\n",
               dirent->kind, (long long)dirent->size, dirent->has_props,
               (long long)dirent->created_rev, (long long)dirent->time,
               dirent->last_author);
      }
  }

  return 0;
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: ra-serf bug

Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
On Thu, May 8, 2008 at 6:05 PM, Eric Gillespie <ep...@pretzelnet.org> wrote:
>  This happens with both 1.5.x and trunk, fresh as of 5 minutes ago
>  (r31106).  The error (but not the double free) goes away if you
>  pass revision instead of SVN_INVALID_REVNUM.

There's something goofy with the pool logic.  If I add:

svn_pool_clear(pool);

to the end of your .c file, I don't get the double free error.  I
don't have the time to chase it further - sorry.  -- justin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org