# [PATCH] http-push: update memory allocation for http headers

3 messages from 2009-01-18 to 2009-01-18. Participants: Ray Chuan, Mike Hommey, Johannes Schindelin.
Thread: https://gitlist.dev/t/17236

## Ray Chuan, 2009-01-18 13:16

Subject: [PATCH] http-push: update memory allocation for http headers
Message-ID: <be6fef0d0901180516q19327c18oa1d7ccc36ce3a87@mail.gmail.com>
URL: https://gitlist.dev/e/be6fef0d0901180516q19327c18oa1d7ccc36ce3a87%40mail.gmail.com

```
In 753bc91 (Remove the requirement opaquelocktoken uri scheme), the
header strings were with the removal "opaquelocktoken:" (16
characters).

Unfortunately, this was without the corresponding change in memory
allocation. In this patch we update these allocations.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 http-push.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/http-push.c b/http-push.c
index a4b7d08..a6522dd 100644
--- a/http-push.c
+++ b/http-push.c
@@ -595,7 +595,7 @@ static int refresh_lock(struct remote_lock *lock)

 	lock->refreshing = 1;

-	if_header = xmalloc(strlen(lock->token) + 25);
+	if_header = xmalloc(strlen(lock->token) + 9);
 	sprintf(if_header, "If: (<%s>)", lock->token);
 	sprintf(timeout_header, "Timeout: Second-%ld", lock->timeout);
 	dav_headers = curl_slist_append(dav_headers, if_header);
@@ -1306,7 +1306,7 @@ static int unlock_remote(struct remote_lock *lock)
 	struct curl_slist *dav_headers = NULL;
 	int rc = 0;

-	lock_token_header = xmalloc(strlen(lock->token) + 31);
+	lock_token_header = xmalloc(strlen(lock->token) + 15);
 	sprintf(lock_token_header, "Lock-Token: <%s>",
 		lock->token);
 	dav_headers = curl_slist_append(dav_headers, lock_token_header);
@@ -1730,7 +1730,7 @@ static int update_remote(unsigned char *sha1,
struct remote_lock *lock)
 	struct buffer out_buffer = { STRBUF_INIT, 0 };
 	struct curl_slist *dav_headers = NULL;

-	if_header = xmalloc(strlen(lock->token) + 25);
+	if_header = xmalloc(strlen(lock->token) + 9);
 	sprintf(if_header, "If: (<%s>)", lock->token);
 	dav_headers = curl_slist_append(dav_headers, if_header);

@@ -1949,7 +1949,7 @@ static void update_remote_info_refs(struct
remote_lock *lock)
 	remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
 		  add_remote_info_ref, &buffer.buf);
 	if (!aborted) {
-		if_header = xmalloc(strlen(lock->token) + 25);
+		if_header = xmalloc(strlen(lock->token) + 9);
 		sprintf(if_header, "If: (<%s>)", lock->token);
 		dav_headers = curl_slist_append(dav_headers, if_header);

-- 
1.6.0.4

```

## Mike Hommey, 2009-01-18 14:20

Subject: Re: [PATCH] http-push: update memory allocation for http headers
Message-ID: <20090118142002.GA18159@glandium.org>
URL: https://gitlist.dev/e/20090118142002.GA18159%40glandium.org
In-Reply-To: <be6fef0d0901180516q19327c18oa1d7ccc36ce3a87@mail.gmail.com>

```
On Sun, Jan 18, 2009 at 09:16:04PM +0800, Ray Chuan wrote:
> In 753bc91 (Remove the requirement opaquelocktoken uri scheme), the
> header strings were with the removal "opaquelocktoken:" (16
> characters).
> 
> Unfortunately, this was without the corresponding change in memory
> allocation. In this patch we update these allocations.
> 
> Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
> ---

It would be better to just turn the whole thing to use strbuf, and/or
extend the patch set I sent earlier today to handle webdav.

Mike

```

## Johannes Schindelin, 2009-01-18 14:55

Subject: Re: [PATCH] http-push: update memory allocation for http headers
Message-ID: <alpine.DEB.1.00.0901181554480.3586@pacific.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0901181554480.3586%40pacific.mpi-cbg.de
In-Reply-To: <be6fef0d0901180516q19327c18oa1d7ccc36ce3a87@mail.gmail.com>

```
Hi,

On Sun, 18 Jan 2009, Ray Chuan wrote:

> In 753bc91 (Remove the requirement opaquelocktoken uri scheme), the
> header strings were with the removal "opaquelocktoken:" (16
> characters).
> 
> Unfortunately, this was without the corresponding change in memory
> allocation. In this patch we update these allocations.

Rather than doing this (which will result in as error-prone code), why 
don't you replace those things by strbufs?

Ciao,
Dscho

```
