From 94932e139d8d58cab65114d340dcf0c201eab125 Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Tue, 28 Sep 2010 21:03:43 -0400 Subject: [PATCH] Fix leak when deleting nonexistent file. --- backend.c | 12 ++++++------ rest.c | 23 +++++++++-------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/backend.c b/backend.c index e76a469..25c2814 100644 --- a/backend.c +++ b/backend.c @@ -121,7 +121,7 @@ bad_delete (const char *bucket, const char *key, const char *url) (void)url; DPRINTF("*** bad call to %s\n",__func__); - return MHD_NO; + return MHD_HTTP_BAD_REQUEST; } int @@ -274,7 +274,7 @@ s3_delete (const char *bucket, const char *key, const char *url) hstor_del(hstor,bucket,key); /* TBD: check return value */ - return MHD_YES; + return MHD_HTTP_OK; } int @@ -682,7 +682,7 @@ curl_delete (const char *bucket, const char *key, const char *url) curl = curl_easy_init(); if (!curl) { - return MHD_NO; + return MHD_HTTP_INTERNAL_SERVER_ERROR; } sprintf(fixed,"http://%s:%u%s",proxy_host,proxy_port,url); @@ -691,7 +691,7 @@ curl_delete (const char *bucket, const char *key, const char *url) curl_easy_perform(curl); curl_easy_cleanup(curl); - return MHD_YES; + return MHD_HTTP_OK; } int @@ -866,10 +866,10 @@ fs_delete (const char *bucket, const char *key, const char *url) if (unlink(url+1) < 0) { error (0, errno, "%s: failed to unlink", url+1); - return MHD_NO; + return MHD_HTTP_NOT_FOUND; } - return MHD_YES; + return MHD_HTTP_OK; } int diff --git a/rest.c b/rest.c index 66f91bb..2172b31 100644 --- a/rest.c +++ b/rest.c @@ -823,7 +823,6 @@ proxy_query (void *cctx, struct MHD_Connection *conn, const char *url, simple_closer(ms); return MHD_NO; } - MHD_add_response_header(resp,"Content-Type","text/xml"); MHD_queue_response(conn,MHD_HTTP_OK,resp); MHD_destroy_response(resp); free_ms(ms); @@ -885,26 +884,23 @@ proxy_delete (void *cctx, struct MHD_Connection *conn, const char *url, DPRINTF("PROXY DELETE %s\n",url); rc = main_func_tbl->delete_func(ms->bucket,ms->key,(char *)url); - if (rc != MHD_YES) { - return rc; + if (rc == MHD_HTTP_OK) { + copied_url = strdup(url); + assert (copied_url); + bucket = strtok_r(copied_url,"/",&stctx); + key = strtok_r(NULL,"/",&stctx); + meta_delete(bucket,key); + free(copied_url); + replicate_delete((char *)url); } - copied_url = strdup(url); - assert (copied_url); - bucket = strtok_r(copied_url,"/",&stctx); - key = strtok_r(NULL,"/",&stctx); - meta_delete(bucket,key); - free(copied_url); - resp = MHD_create_response_from_data(0,NULL,MHD_NO,MHD_NO); if (!resp) { return MHD_NO; } - MHD_add_response_header(resp,"Content-Type","text/xml"); - MHD_queue_response(conn,MHD_HTTP_OK,resp); + MHD_queue_response(conn,rc,resp); MHD_destroy_response(resp); - replicate_delete((char *)url); free_ms(ms); return MHD_YES; } @@ -1026,7 +1022,6 @@ proxy_api_root (void *cctx, struct MHD_Connection *conn, const char *url, if (!resp) { return MHD_NO; } - MHD_add_response_header(resp,"Content-Type","text/xml"); MHD_queue_response(conn,rc,resp); MHD_destroy_response(resp); -- 2.11.4.GIT