Use gpg_error_from_syserror instead of directly accessing errno.

--

Also fixed a couple of minor thing; e.g. save the error before calling
cleanup functions.  Do not save the errno if only free is called
in between.
This commit is contained in:
Werner Koch 2013-02-06 17:35:40 +01:00
parent 322552a88d
commit 51fd6d8292
27 changed files with 133 additions and 135 deletions

View File

@ -60,7 +60,7 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
if (fname)
stream = fopen (fname, "rb");
if (!stream)
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (gpg_error_from_syserror ());
#ifdef HAVE_FSEEKO
res = fseeko (stream, offset, SEEK_SET);
@ -71,31 +71,31 @@ gpgme_data_new_from_filepart (gpgme_data_t *r_dh, const char *fname,
if (res)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
if (fname)
fclose (stream);
return TRACE_ERR (gpg_error_from_errno (saved_errno));
return TRACE_ERR (saved_err);
}
buf = malloc (length);
if (!buf)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
if (fname)
fclose (stream);
return TRACE_ERR (gpg_error_from_errno (saved_errno));
return TRACE_ERR (saved_err);
}
while (fread (buf, length, 1, stream) < 1
&& ferror (stream) && errno == EINTR);
if (ferror (stream))
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
if (buf)
free (buf);
if (fname)
fclose (stream);
return TRACE_ERR (gpg_error_from_errno (saved_errno));
return TRACE_ERR (saved_err);
}
if (fname)
@ -135,7 +135,7 @@ gpgme_data_new_from_file (gpgme_data_t *r_dh, const char *fname, int copy)
return TRACE_ERR (gpg_error (GPG_ERR_INV_VALUE));
if (stat (fname, &statbuf) < 0)
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (gpg_error_from_syserror ());
err = gpgme_data_new_from_filepart (r_dh, fname, NULL, 0, statbuf.st_size);
return TRACE_ERR (err);
@ -247,8 +247,8 @@ gpgme_data_rewind (gpgme_data_t dh)
gpgme_error_t err;
TRACE_BEG (DEBUG_DATA, "gpgme_data_rewind", dh);
err = (gpgme_data_seek (dh, 0, SEEK_SET) == -1)
? gpg_error_from_errno (errno) : 0;
err = ((gpgme_data_seek (dh, 0, SEEK_SET) == -1)
? gpg_error_from_syserror () : 0);
return TRACE_ERR (err);
}

View File

@ -202,9 +202,9 @@ gpgme_data_new_from_mem (gpgme_data_t *r_dh, const char *buffer,
char *bufcpy = malloc (size);
if (!bufcpy)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
_gpgme_data_release (*r_dh);
return TRACE_ERR (gpg_error_from_errno (saved_errno));
return TRACE_ERR (saved_err);
}
memcpy (bufcpy, buffer, size);
(*r_dh)->data.mem.buffer = bufcpy;
@ -242,9 +242,9 @@ gpgme_data_release_and_get_mem (gpgme_data_t dh, size_t *r_len)
str = malloc (dh->data.mem.length);
if (!str)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
gpgme_data_release (dh);
TRACE_ERR (gpg_error_from_errno (saved_errno));
TRACE_ERR (saved_err);
return NULL;
}
memcpy (str, dh->data.mem.orig_buffer, dh->data.mem.length);

View File

@ -394,7 +394,7 @@ llass_set_locale (void *engine, int category, const char *value)
return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
else
{
err = assuan_transact (llass->assuan_ctx, optstr, NULL, NULL,

View File

@ -225,7 +225,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
g13 = calloc (1, sizeof *g13);
if (!g13)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
g13->status_cb.fd = -1;
g13->status_cb.dir = 1;
@ -269,7 +269,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{
free (dft_display);
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
goto leave;
}
free (dft_display);
@ -295,7 +295,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
{
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
goto leave;
}
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL, NULL,
@ -312,7 +312,7 @@ g13_new (void **engine, const char *file_name, const char *home_dir)
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{
free (dft_ttytype);
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
goto leave;
}
free (dft_ttytype);
@ -390,7 +390,7 @@ g13_set_locale (void *engine, int category, const char *value)
return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
else
{
err = assuan_transact (g13->assuan_ctx, optstr, NULL, NULL,

View File

@ -210,7 +210,7 @@ _add_arg (engine_gpg_t gpg, const char *arg, int front, int *arg_locp)
a = malloc (sizeof *a + strlen (arg));
if (!a)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
a->data = NULL;
a->dup_to = -1;
@ -269,7 +269,7 @@ add_data (engine_gpg_t gpg, gpgme_data_t data, int dup_to, int inbound)
a = malloc (sizeof *a - 1);
if (!a)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
a->next = NULL;
a->data = data;
a->inbound = inbound;
@ -424,14 +424,14 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
gpg = calloc (1, sizeof *gpg);
if (!gpg)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
if (file_name)
{
gpg->file_name = strdup (file_name);
if (!gpg->file_name)
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
goto leave;
}
}
@ -452,14 +452,14 @@ gpg_new (void **engine, const char *file_name, const char *home_dir)
gpg->status.buffer = malloc (gpg->status.bufsize);
if (!gpg->status.buffer)
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
goto leave;
}
/* In any case we need a status pipe - create it right here and
don't handle it with our generic gpgme_data_t mechanism. */
if (_gpgme_io_pipe (gpg->status.fd, 1) == -1)
{
rc = gpg_error_from_errno (errno);
rc = gpg_error_from_syserror ();
goto leave;
}
if (_gpgme_io_set_close_notify (gpg->status.fd[0],
@ -630,14 +630,14 @@ gpg_set_colon_line_handler (void *engine, engine_colon_line_handler_t fnc,
gpg->colon.readpos = 0;
gpg->colon.buffer = malloc (gpg->colon.bufsize);
if (!gpg->colon.buffer)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
if (_gpgme_io_pipe (gpg->colon.fd, 1) == -1)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (gpg->colon.buffer);
gpg->colon.buffer = NULL;
return gpg_error_from_errno (saved_errno);
return saved_err;
}
if (_gpgme_io_set_close_notify (gpg->colon.fd[0], close_notify_handler, gpg)
|| _gpgme_io_set_close_notify (gpg->colon.fd[1],
@ -775,23 +775,23 @@ build_argv (engine_gpg_t gpg)
argv = calloc (argc + 1, sizeof *argv);
if (!argv)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
fd_data_map = calloc (datac + 1, sizeof *fd_data_map);
if (!fd_data_map)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc = datac = 0;
argv[argc] = strdup ("gpg"); /* argv[0] */
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc++;
if (need_special)
@ -799,10 +799,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup ("--enable-special-filenames");
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc++;
}
@ -811,10 +811,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup ("--use-agent");
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc++;
}
@ -823,20 +823,20 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup ("--batch");
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc++;
}
argv[argc] = strdup ("--no-sk-comment");
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc++;
for (a = gpg->arglist; a; a = a->next)
@ -908,10 +908,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = malloc (buflen);
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
ptr = argv[argc];
@ -933,10 +933,10 @@ build_argv (engine_gpg_t gpg)
argv[argc] = strdup (a->arg);
if (!argv[argc])
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fd_data_map);
free_argv (argv);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
argc++;
}
@ -987,13 +987,13 @@ read_status (engine_gpg_t gpg)
bufsize += 1024;
buffer = realloc (buffer, bufsize);
if (!buffer)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
nread = _gpgme_io_read (gpg->status.fd[0],
buffer + readpos, bufsize-readpos);
if (nread == -1)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
if (!nread)
{
@ -1043,7 +1043,7 @@ read_status (engine_gpg_t gpg)
free (gpg->cmd.keyword);
gpg->cmd.keyword = strdup (rest);
if (!gpg->cmd.keyword)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
/* This should be the last thing we have
received and the next thing will be that
the command handler does its action. */
@ -1163,12 +1163,12 @@ read_colon_line (engine_gpg_t gpg)
bufsize += 1024;
buffer = realloc (buffer, bufsize);
if (!buffer)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
nread = _gpgme_io_read (gpg->colon.fd[0], buffer+readpos, bufsize-readpos);
if (nread == -1)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
if (!nread)
{
@ -1259,7 +1259,6 @@ static gpgme_error_t
start (engine_gpg_t gpg)
{
gpgme_error_t rc;
int saved_errno;
int i, n;
int status;
struct spawn_fd_item_s *fd_list;
@ -1299,7 +1298,7 @@ start (engine_gpg_t gpg)
n++;
fd_list = calloc (n, sizeof *fd_list);
if (! fd_list)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
/* Build the fd list for the child. */
n = 0;
@ -1327,11 +1326,12 @@ start (engine_gpg_t gpg)
_gpgme_get_gpg_path (), gpg->argv,
IOSPAWN_FLAG_ALLOW_SET_FG,
fd_list, NULL, NULL, &pid);
saved_errno = errno;
free (fd_list);
if (status == -1)
return gpg_error_from_errno (saved_errno);
{
int saved_err = gpg_error_from_syserror ();
free (fd_list);
if (status == -1)
return saved_err;
}
/*_gpgme_register_term_handler ( closure, closure_value, pid );*/
@ -1495,7 +1495,7 @@ append_args_from_sig_notations (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */)
arg = malloc (1 + notation->name_len + 1 + notation->value_len + 1);
if (!arg)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
if (!err)
{
@ -1531,7 +1531,7 @@ append_args_from_sig_notations (engine_gpg_t gpg, gpgme_ctx_t ctx /* FIXME */)
{
value = malloc (1 + notation->value_len + 1);
if (!value)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
else
{
value[0] = '!';
@ -2061,7 +2061,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
if (asprintf (r_line, "pub:o%s:%s:%s:%s:%s:%s::::::::",
field[6], field[3], field[2], field[1],
field[4], field[5]) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
return 0;
case RT_UID:
@ -2086,7 +2086,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
char *dst;
if (! uid)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
src = field[1];
dst = uid;
while (*src)
@ -2114,7 +2114,7 @@ gpg_keylist_preprocess (char *line, char **r_line)
if (asprintf (r_line, "uid:o%s::::%s:%s:::%s:",
field[4], field[2], field[3], uid) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
return 0;

View File

@ -96,7 +96,7 @@ gpgconf_new (void **engine, const char *file_name, const char *home_dir)
gpgconf = calloc (1, sizeof *gpgconf);
if (!gpgconf)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
gpgconf->file_name = strdup (file_name ? file_name
: _gpgme_get_gpgconf_path ());

View File

@ -1196,9 +1196,9 @@ set_recipients (engine_gpgsm_t gpgsm, gpgme_key_t recp[])
char *newline = realloc (line, newlen);
if (! newline)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (line);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
line = newline;
linelen = newlen;

View File

@ -308,8 +308,8 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
{
if (asprintf (&optstr, "OPTION display=%s", dft_display) < 0)
{
err = gpg_error_from_syserror ();
free (dft_display);
err = gpg_error_from_errno (errno);
goto leave;
}
free (dft_display);
@ -335,7 +335,7 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
{
if (asprintf (&optstr, "OPTION ttyname=%s", dft_ttyname) < 0)
{
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
goto leave;
}
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL, NULL,
@ -351,8 +351,8 @@ uiserver_new (void **engine, const char *file_name, const char *home_dir)
{
if (asprintf (&optstr, "OPTION ttytype=%s", dft_ttytype) < 0)
{
err = gpg_error_from_syserror ();
free (dft_ttytype);
err = gpg_error_from_errno (errno);
goto leave;
}
free (dft_ttytype);
@ -425,7 +425,7 @@ uiserver_set_locale (void *engine, int category, const char *value)
return 0;
if (asprintf (&optstr, "OPTION %s=%s", catstr, value) < 0)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
else
{
err = assuan_transact (uiserver->assuan_ctx, optstr, NULL, NULL,
@ -553,7 +553,7 @@ uiserver_set_fd (engine_uiserver_t uiserver, fd_type_t fd_type, const char *opt)
int fds[2];
if (_gpgme_io_pipe (fds, 0) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
iocb_data->fd = dir ? fds[0] : fds[1];
iocb_data->server_fd = dir ? fds[1] : fds[0];
@ -694,7 +694,7 @@ status_handler (void *opaque, int fd)
{
char *newline = realloc (*aline, *alinelen + linelen + 1);
if (!newline)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
else
{
*aline = newline;
@ -779,7 +779,7 @@ status_handler (void *opaque, int fd)
if (!nwritten || (nwritten < 0 && errno != EINTR)
|| nwritten > linelen)
{
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
break;
}
src += nwritten;
@ -943,7 +943,7 @@ _uiserver_decrypt (void *engine, int verify,
if (asprintf (&cmd, "DECRYPT%s%s", protocol,
verify ? "" : " --no-verify") < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
uiserver->input_cb.data = ciph;
err = uiserver_set_fd (uiserver, INPUT_FD,
@ -995,7 +995,7 @@ set_recipients (engine_uiserver_t uiserver, gpgme_key_t recp[])
linelen = 10 + 40 + 1; /* "RECIPIENT " + guess + '\0'. */
line = malloc (10 + 40 + 1);
if (!line)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
strcpy (line, "RECIPIENT ");
for (i=0; !err && recp[i]; i++)
{
@ -1015,9 +1015,9 @@ set_recipients (engine_uiserver_t uiserver, gpgme_key_t recp[])
char *newline = realloc (line, newlen);
if (! newline)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (line);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
line = newline;
linelen = newlen;
@ -1070,7 +1070,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
if (asprintf (&cmd, "PREP_ENCRYPT%s%s", protocol,
(flags & GPGME_ENCRYPT_EXPECT_SIGN)
? " --expect-sign" : "") < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
else
{
@ -1078,7 +1078,7 @@ uiserver_encrypt (void *engine, gpgme_key_t recp[], gpgme_encrypt_flags_t flags,
return gpg_error (GPG_ERR_INV_VALUE);
if (asprintf (&cmd, "ENCRYPT%s", protocol) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
if (plain)
@ -1147,7 +1147,7 @@ uiserver_sign (void *engine, gpgme_data_t in, gpgme_data_t out,
if (asprintf (&cmd, "SIGN%s%s", protocol,
(mode == GPGME_SIG_MODE_DETACH) ? " --detached" : "") < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
key = gpgme_signers_enum (ctx, 0);
if (key)
@ -1222,7 +1222,7 @@ uiserver_verify (void *engine, gpgme_data_t sig, gpgme_data_t signed_text,
return gpgme_error (GPG_ERR_UNSUPPORTED_PROTOCOL);
if (asprintf (&cmd, "VERIFY%s", protocol) < 0)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
uiserver->input_cb.data = sig;
err = uiserver_set_fd (uiserver, INPUT_FD,

View File

@ -226,7 +226,7 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
*lastp = malloc (sizeof (*engine_info));
if (!*lastp || !file_name)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
_gpgme_engine_info_release (engine_info);
engine_info = NULL;
@ -237,7 +237,7 @@ gpgme_get_engine_info (gpgme_engine_info_t *info)
free (home_dir);
UNLOCK (engine_info_lock);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
(*lastp)->protocol = proto_list[proto];
@ -294,7 +294,7 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
{
home_dir = strdup (info->home_dir);
if (!home_dir)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
}
else
home_dir = NULL;
@ -303,7 +303,7 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
{
version = strdup (info->version);
if (!version)
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
}
else
version = NULL;
@ -311,7 +311,7 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
*lastp = malloc (sizeof (*engine_info));
if (!*lastp || !file_name || err)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
_gpgme_engine_info_release (new_info);
@ -323,7 +323,7 @@ _gpgme_engine_info_copy (gpgme_engine_info_t *r_info)
free (version);
UNLOCK (engine_info_lock);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
(*lastp)->protocol = info->protocol;
@ -372,7 +372,7 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
new_file_name = strdup (ofile_name);
}
if (!new_file_name)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
if (home_dir)
{
@ -380,7 +380,7 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
if (!new_home_dir)
{
free (new_file_name);
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
}
else
@ -392,7 +392,7 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto,
if (!new_home_dir)
{
free (new_file_name);
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
}
else
@ -454,7 +454,7 @@ _gpgme_engine_new (gpgme_engine_info_t info, engine_t *r_engine)
engine = calloc (1, sizeof *engine);
if (!engine)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
engine->ops = engine_ops[info->protocol];
if (engine->ops->new)

View File

@ -113,7 +113,7 @@ genkey_status_handler (void *priv, gpgme_status_code_t code, char *args)
free (opd->result.fpr);
opd->result.fpr = strdup (&args[2]);
if (!opd->result.fpr)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
}
break;

View File

@ -46,7 +46,7 @@ _gpgme_getenv (const char *name, char **value)
{
*value = strdup (env_value);
if (!*value)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
return 0;
}

View File

@ -1614,7 +1614,7 @@ gt_recipients_add (gpgme_tool_t gt, const char *pattern)
gpgme_key_t key;
if (gt->recipients_nr >= MAX_RECIPIENTS)
return gpg_error_from_errno (ENOMEM);
return gpg_error (GPG_ERR_ENOMEM);
if (gpgme_get_protocol (gt->ctx) == GPGME_PROTOCOL_UISERVER)
err = gpgme_key_from_uid (&key, pattern);

View File

@ -87,7 +87,7 @@ gpgme_new (gpgme_ctx_t *r_ctx)
ctx = calloc (1, sizeof *ctx);
if (!ctx)
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (gpg_error_from_syserror ());
INIT_LOCK (ctx->lock);
@ -95,7 +95,7 @@ gpgme_new (gpgme_ctx_t *r_ctx)
if (!ctx->engine_info)
{
free (ctx);
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (gpg_error_from_syserror ());
}
ctx->keylist_mode = GPGME_KEYLIST_MODE_LOCAL;
@ -110,10 +110,11 @@ gpgme_new (gpgme_ctx_t *r_ctx)
ctx->lc_ctype = strdup (def_lc_ctype);
if (!ctx->lc_ctype)
{
int saved_err = gpg_error_from_syserror ();
UNLOCK (def_lc_lock);
_gpgme_engine_info_release (ctx->engine_info);
free (ctx);
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (saved_err);
}
}
else
@ -124,12 +125,13 @@ gpgme_new (gpgme_ctx_t *r_ctx)
ctx->lc_messages = strdup (def_lc_messages);
if (!ctx->lc_messages)
{
int saved_err = gpg_error_from_syserror ();
UNLOCK (def_lc_lock);
if (ctx->lc_ctype)
free (ctx->lc_ctype);
_gpgme_engine_info_release (ctx->engine_info);
free (ctx);
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (saved_err);
}
}
else
@ -676,14 +678,14 @@ gpgme_set_locale (gpgme_ctx_t ctx, int category, const char *value)
if (failed)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
if (new_lc_ctype)
free (new_lc_ctype);
if (new_lc_messages)
free (new_lc_messages);
return TRACE_ERR (gpg_error_from_errno (saved_errno));
return TRACE_ERR (saved_err);
}
#define SET_ONE_LOCALE(lcat, ucat) \

View File

@ -174,9 +174,8 @@ parse_import (char *args, gpgme_import_status_t *import_status, int problem)
import->fpr = strdup (args);
if (!import->fpr)
{
int saved_errno = errno;
free (import);
return gpg_error_from_errno (saved_errno);
return gpg_error_from_syserror ();
}
*import_status = import;

View File

@ -46,7 +46,7 @@ _gpgme_key_new (gpgme_key_t *r_key)
key = calloc (1, sizeof *key);
if (!key)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
key->_refs = 1;
*r_key = key;
@ -61,7 +61,7 @@ _gpgme_key_add_subkey (gpgme_key_t key, gpgme_subkey_t *r_subkey)
subkey = calloc (1, sizeof *subkey);
if (!subkey)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
subkey->keyid = subkey->_keyid;
subkey->_keyid[16] = '\0';
@ -215,7 +215,7 @@ _gpgme_key_append_name (gpgme_key_t key, const char *src, int convert)
size, so that we are able to store the parsed stuff there too. */
uid = malloc (sizeof (*uid) + 2 * src_len + 3);
if (!uid)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
memset (uid, 0, sizeof *uid);
uid->uid = ((char *) uid) + sizeof (*uid);

View File

@ -558,7 +558,7 @@ keylist_colon_handler (void *priv, char *line)
{
key->issuer_serial = strdup (field[7]);
if (!key->issuer_serial)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
/* Field 9 has the ownertrust. */
@ -653,7 +653,7 @@ keylist_colon_handler (void *priv, char *line)
if (fields >= 10)
{
if (_gpgme_key_append_name (key, field[9], 1))
return gpg_error_from_errno (GPG_ERR_ENOMEM); /* FIXME */
return gpg_error (GPG_ERR_ENOMEM); /* FIXME */
else
{
if (field[1])
@ -674,7 +674,7 @@ keylist_colon_handler (void *priv, char *line)
{
subkey->fpr = strdup (field[9]);
if (!subkey->fpr)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
}
@ -683,7 +683,7 @@ keylist_colon_handler (void *priv, char *line)
{
key->chain_id = strdup (field[12]);
if (!key->chain_id)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
}
break;

View File

@ -56,7 +56,7 @@ _gpgme_op_data_lookup (gpgme_ctx_t ctx, ctx_op_data_id_t type, void **hook,
data = calloc (1, sizeof (struct ctx_op_data) + size);
if (!data)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
data->magic = CTX_OP_DATA_MAGIC;
data->next = ctx->op_data;
data->type = type;
@ -192,7 +192,7 @@ _gpgme_parse_inv_recp (char *args, gpgme_invalid_key_t *key)
inv_key = malloc (sizeof (*inv_key));
if (!inv_key)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
inv_key->next = NULL;
gpg_err_set_errno (0);
reason = strtol (args, &tail, 0);
@ -266,9 +266,8 @@ _gpgme_parse_inv_recp (char *args, gpgme_invalid_key_t *key)
inv_key->fpr = strdup (tail);
if (!inv_key->fpr)
{
int saved_errno = errno;
free (inv_key);
return gpg_error_from_errno (saved_errno);
return gpg_error_from_syserror ();
}
}
else

View File

@ -77,7 +77,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
if (opd->uid_hint)
free (opd->uid_hint);
if (!(opd->uid_hint = strdup (args)))
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
break;
case GPGME_STATUS_BAD_PASSPHRASE:
@ -97,7 +97,7 @@ _gpgme_passphrase_status_handler (void *priv, gpgme_status_code_t code,
free (opd->passphrase_info);
opd->passphrase_info = strdup (args);
if (!opd->passphrase_info)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
break;
case GPGME_STATUS_MISSING_PASSPHRASE:

View File

@ -47,7 +47,7 @@ _gpgme_progress_status_handler (void *priv, gpgme_status_code_t code,
args_cpy = strdup (args);
if (!args_cpy)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
p = strchr (args_cpy, ' ');
if (p)

View File

@ -79,7 +79,7 @@ _gpgme_sig_notation_create (gpgme_sig_notation_t *notationp,
notation = calloc (1, sizeof (*notation));
if (!notation)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
/* This is critical. We want to reliably identify policy URLs by
using a NULL pointer for NAME. So all notations must have a NAME
@ -91,7 +91,7 @@ _gpgme_sig_notation_create (gpgme_sig_notation_t *notationp,
notation->name = malloc (name_len + 1);
if (!notation->name)
{
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
goto err;
}
@ -107,7 +107,7 @@ _gpgme_sig_notation_create (gpgme_sig_notation_t *notationp,
notation->value = malloc (value_len + 1);
if (!notation->value)
{
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
goto err;
}

View File

@ -234,9 +234,8 @@ parse_sig_created (char *args, gpgme_new_signature_t *sigp)
sig->fpr = strdup (args);
if (!sig->fpr)
{
int saved_errno = errno;
free (sig);
return gpg_error_from_errno (saved_errno);
return gpg_error_from_syserror ();
}
*sigp = sig;
return 0;

View File

@ -80,7 +80,7 @@ gpgme_signers_add (gpgme_ctx_t ctx, const gpgme_key_t key)
newarr = realloc (ctx->signers, n * sizeof (*newarr));
if (!newarr)
return TRACE_ERR (gpg_error_from_errno (errno));
return TRACE_ERR (gpg_error_from_syserror ());
for (j = ctx->signers_size; j < n; j++)
newarr[j] = NULL;
ctx->signers = newarr;

View File

@ -47,7 +47,7 @@ _gpgme_trust_item_new (gpgme_trust_item_t *r_item)
item = calloc (1, sizeof *item);
if (!item)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
item->_refs = 1;
item->keyid = item->_keyid;
item->_keyid[16] = '\0';

View File

@ -111,9 +111,9 @@ trustlist_colon_handler (void *priv, char *line)
item->name = strdup (p);
if (!item->name)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
gpgme_trust_item_unref (item);
return gpg_error_from_errno (saved_errno);
return saved_err;
}
break;
}

View File

@ -97,7 +97,7 @@ ctx_active (gpgme_ctx_t ctx)
{
struct ctx_list_item *li = malloc (sizeof (struct ctx_list_item));
if (!li)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
li->ctx = ctx;
LOCK (ctx_list_lock);
@ -269,10 +269,10 @@ gpgme_wait_ext (gpgme_ctx_t ctx, gpgme_error_t *status,
fdt.fds = malloc (i * sizeof (struct io_select_fd_s));
if (!fdt.fds)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
UNLOCK (ctx_list_lock);
if (status)
*status = gpg_error_from_errno (saved_errno);
*status = saved_err;
if (op_err)
*op_err = 0;
return NULL;
@ -290,10 +290,10 @@ gpgme_wait_ext (gpgme_ctx_t ctx, gpgme_error_t *status,
nr = _gpgme_io_select (fdt.fds, fdt.size, 0);
if (nr < 0)
{
int saved_errno = errno;
int saved_err = gpg_error_from_syserror ();
free (fdt.fds);
if (status)
*status = gpg_error_from_errno (saved_errno);
*status = saved_err;
if (op_err)
*op_err = 0;
return NULL;

View File

@ -91,7 +91,7 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond,
{
/* An error occured. Close all fds in this context, and
signal it. */
err = gpg_error_from_errno (errno);
err = gpg_error_from_syserror ();
_gpgme_cancel_with_err (ctx, err, 0);
return err;

View File

@ -73,7 +73,7 @@ fd_table_put (fd_table_t fdt, int fd, int dir, void *opaque, int *idx)
new_fds = realloc (fdt->fds, (fdt->size + FDT_ALLOCSIZE)
* sizeof (*new_fds));
if (!new_fds)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
fdt->fds = new_fds;
fdt->size += FDT_ALLOCSIZE;
@ -113,16 +113,15 @@ _gpgme_add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
tag = malloc (sizeof *tag);
if (!tag)
return gpg_error_from_errno (errno);
return gpg_error_from_syserror ();
tag->ctx = ctx;
/* Allocate a structure to hold information about the handler. */
item = calloc (1, sizeof *item);
if (!item)
{
int saved_errno = errno;
free (tag);
return gpg_error_from_errno (saved_errno);
return gpg_error_from_syserror ();
}
item->ctx = ctx;
item->dir = dir;