guile-user
[Top][All Lists]
Advanced

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

RPC xdr_free segmentation fault


From: Tomas By
Subject: RPC xdr_free segmentation fault
Date: Mon, 10 Nov 2014 01:37:00 +0100
User-agent: SquirrelMail/1.4.18

Hi all,

I'm trying to write a Guile/C RPC client (I know about guile-rpc but would
like to get this working also).

The dir.x and server code is the standard RPC example. I have only
modified the client (code below).

It works fine as far as the xdr_free at the bottom, which causes a
segmentation fault.

Any help appreciated.

/Tomas



---------- begin client.c ----------
#include <stdio.h>
#include "dir.h" /* generated by rpcgen */
#include <errno.h>
#include <libguile.h>

CLIENT* clnt;

SCM readdir_wrapper(SCM o) {
  if (scm_is_string(o)) {
    char* s;
    readdir_res* result;
    namelist nl;
    scm_dynwind_begin(0);
    s = scm_to_locale_string(o);
    scm_dynwind_free(s);
    result = readdir_1(s,clnt);
    scm_dynwind_end();
    if (result == (readdir_res*)NULL) {
      clnt_perror(clnt,"localhost");
    } else {
      if (result->erna != 0) {
        errno = result->erna;
        perror(s);
      } else {
        for (nl = result->readdir_res_u.list; nl != NULL; nl = nl->next) {
          printf("%s\n",nl->name);
        }
        printf("\n");
      }
      xdr_free((xdrproc_t)xdr_readdir_res,(char*)result);
    }
  } else {
    scm_wrong_type_arg("read-dir",1,o);
  }
}

static void inner_main(void* data,int argc,char** argv) {
  scm_c_define_gsubr("read-dir",1,0,0,readdir_wrapper);
  scm_shell(argc,argv);
}

int main(int argc,char* argv[]) {
  clnt = clnt_create("localhost",DIRPROG,DIRVERS,"tcp");
  if (clnt == (CLIENT*)NULL) {
    clnt_pcreateerror("localhost");
    exit(1);
  }
  scm_boot_guile(argc,argv,inner_main,NULL);
  /*clnt_destroy(clnt);*/
  return 0;
}
---------- end client.c ----------





reply via email to

[Prev in Thread] Current Thread [Next in Thread]