summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-04-04 18:17:11 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-04-04 18:17:11 +0200
commitdc4822837ccfac9d1f100f8e0e5d59910121ca95 (patch)
tree914573ea4bbe3b1209b7667f4a02f0ca4a2720a1
parent7921208aba851b1e7565f58ac957f81e1e16200a (diff)
fb-helper: properly clean up upon error
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--fb-helper.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/fb-helper.c b/fb-helper.c
index c012c9f..ee6fe60 100644
--- a/fb-helper.c
+++ b/fb-helper.c
@@ -245,13 +245,15 @@ int main(int argc, char *argv[])
/* initialize curl */
if (curl_global_init(CURL_GLOBAL_ALL) != 0) {
fprintf(stderr, "Error initializing curl");
- return 10;
+ ret = 10;
+ goto cleanup;
}
curl = curl_easy_init();
if(!curl) {
fprintf(stderr, "Error initializing curl");
- return 1;
+ ret = 1;
+ goto cleanup;
}
/* if we have a file to upload, add it as a POST request */
@@ -261,7 +263,8 @@ int main(int argc, char *argv[])
if(stat(file, &statbuf) == -1) {
fprintf(stderr, "fb-helper: %s: ", file);
perror(NULL);
- return 1;
+ ret = 1;
+ goto cleanup;
}
/* load files with 0 size (/proc files for example) into memory so we can
@@ -270,7 +273,8 @@ int main(int argc, char *argv[])
size_t data_size = 0;
if (load_file(file, &data, &data_size) != 0) {
- return 1;
+ ret = 1;
+ goto cleanup;
}
forms[0].option = CURLFORM_BUFFER;
@@ -329,9 +333,10 @@ int main(int argc, char *argv[])
if (res != 0) {
fprintf(stderr, "\n%s\n", curl_easy_strerror(res));
ret = 1;
+ goto cleanup;
}
- /* cleanup */
+cleanup:
curl_easy_cleanup(curl);
if (formpost)