Skip to content

Commit 68a65f5

Browse files
drafnelgitster
authored andcommitted
contrib/git-credential-gnome-keyring.c: use glib memory allocation functions
Rather than roll our own, let's use the memory allocation/free routines provided by glib. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da2727f commit 68a65f5

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

contrib/credential/gnome-keyring/git-credential-gnome-keyring.c

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <string.h>
2828
#include <stdarg.h>
2929
#include <stdlib.h>
30-
#include <errno.h>
3130
#include <glib.h>
3231
#include <gnome-keyring.h>
3332
#include <gnome-keyring-memory.h>
@@ -83,21 +82,6 @@ static inline void error(const char *fmt, ...)
8382
va_end(ap);
8483
}
8584

86-
static inline void die_errno(int err)
87-
{
88-
error("%s", strerror(err));
89-
exit(EXIT_FAILURE);
90-
}
91-
92-
static inline char *xstrdup(const char *str)
93-
{
94-
char *ret = strdup(str);
95-
if (!ret)
96-
die_errno(errno);
97-
98-
return ret;
99-
}
100-
10185
/* ----------------- GNOME Keyring functions ----------------- */
10286

10387
/* create a special keyring option string, if path is given */
@@ -134,7 +118,7 @@ static int keyring_get(struct credential *c)
134118
c->port,
135119
&entries);
136120

137-
free(object);
121+
g_free(object);
138122

139123
if (result == GNOME_KEYRING_RESULT_NO_MATCH)
140124
return EXIT_SUCCESS;
@@ -154,7 +138,7 @@ static int keyring_get(struct credential *c)
154138
c->password = gnome_keyring_memory_strdup(password_data->password);
155139

156140
if (!c->username)
157-
c->username = xstrdup(password_data->user);
141+
c->username = g_strdup(password_data->user);
158142

159143
gnome_keyring_network_password_list_free(entries);
160144

@@ -192,7 +176,7 @@ static int keyring_store(struct credential *c)
192176
c->password,
193177
&item_id);
194178

195-
free(object);
179+
g_free(object);
196180
return EXIT_SUCCESS;
197181
}
198182

@@ -226,7 +210,7 @@ static int keyring_erase(struct credential *c)
226210
c->port,
227211
&entries);
228212

229-
free(object);
213+
g_free(object);
230214

231215
if (result == GNOME_KEYRING_RESULT_NO_MATCH)
232216
return EXIT_SUCCESS;
@@ -278,10 +262,10 @@ static void credential_init(struct credential *c)
278262

279263
static void credential_clear(struct credential *c)
280264
{
281-
free(c->protocol);
282-
free(c->host);
283-
free(c->path);
284-
free(c->username);
265+
g_free(c->protocol);
266+
g_free(c->host);
267+
g_free(c->path);
268+
g_free(c->username);
285269
gnome_keyring_memory_free(c->password);
286270

287271
credential_init(c);
@@ -315,22 +299,22 @@ static int credential_read(struct credential *c)
315299
*value++ = '\0';
316300

317301
if (!strcmp(key, "protocol")) {
318-
free(c->protocol);
319-
c->protocol = xstrdup(value);
302+
g_free(c->protocol);
303+
c->protocol = g_strdup(value);
320304
} else if (!strcmp(key, "host")) {
321-
free(c->host);
322-
c->host = xstrdup(value);
305+
g_free(c->host);
306+
c->host = g_strdup(value);
323307
value = strrchr(c->host,':');
324308
if (value) {
325309
*value++ = '\0';
326310
c->port = atoi(value);
327311
}
328312
} else if (!strcmp(key, "path")) {
329-
free(c->path);
330-
c->path = xstrdup(value);
313+
g_free(c->path);
314+
c->path = g_strdup(value);
331315
} else if (!strcmp(key, "username")) {
332-
free(c->username);
333-
c->username = xstrdup(value);
316+
g_free(c->username);
317+
c->username = g_strdup(value);
334318
} else if (!strcmp(key, "password")) {
335319
gnome_keyring_memory_free(c->password);
336320
c->password = gnome_keyring_memory_strdup(value);

0 commit comments

Comments
 (0)