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 <drafnel@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Sep 23, 2013 at 11:49 UTC 68a65f5fe54c2b21bfe16ef3a0b48956ecf5658a
1 file changed +16 -32
contrib/credential/gnome-keyring/git-credential-gnome-keyring.c
+16 -32
@@ -27,7 +27,6 @@
27 #include <string.h>
28 #include <stdarg.h>
29 #include <stdlib.h>
30 -#include <errno.h>
30 #include <glib.h>
31 #include <gnome-keyring.h>
32 #include <gnome-keyring-memory.h>
@@ -83,21 +82,6 @@ static inline void error(const char *fmt, ...)
82 va_end(ap);
83 }
84
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 -
85 /* ----------------- GNOME Keyring functions ----------------- */
86
87 /* create a special keyring option string, if path is given */
@@ -134,7 +118,7 @@ static int keyring_get(struct credential *c)
118 c->port,
119 &entries);
120
137 - free(object);
121 + g_free(object);
122
123 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
124 return EXIT_SUCCESS;
@@ -154,7 +138,7 @@ static int keyring_get(struct credential *c)
138 c->password = gnome_keyring_memory_strdup(password_data->password);
139
140 if (!c->username)
157 - c->username = xstrdup(password_data->user);
141 + c->username = g_strdup(password_data->user);
142
143 gnome_keyring_network_password_list_free(entries);
144
@@ -192,7 +176,7 @@ static int keyring_store(struct credential *c)
176 c->password,
177 &item_id);
178
195 - free(object);
179 + g_free(object);
180 return EXIT_SUCCESS;
181 }
182
@@ -226,7 +210,7 @@ static int keyring_erase(struct credential *c)
210 c->port,
211 &entries);
212
229 - free(object);
213 + g_free(object);
214
215 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
216 return EXIT_SUCCESS;
@@ -278,10 +262,10 @@ static void credential_init(struct credential *c)
262
263 static void credential_clear(struct credential *c)
264 {
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);
269 gnome_keyring_memory_free(c->password);
270
271 credential_init(c);
@@ -315,22 +299,22 @@ static int credential_read(struct credential *c)
299 *value++ = '\0';
300
301 if (!strcmp(key, "protocol")) {
318 - free(c->protocol);
319 - c->protocol = xstrdup(value);
302 + g_free(c->protocol);
303 + c->protocol = g_strdup(value);
304 } 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);
307 value = strrchr(c->host,':');
308 if (value) {
309 *value++ = '\0';
310 c->port = atoi(value);
311 }
312 } 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);
315 } 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);
318 } else if (!strcmp(key, "password")) {
319 gnome_keyring_memory_free(c->password);
320 c->password = gnome_keyring_memory_strdup(value);