mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 06:41:32 +02:00
MEDIUM: buffer: always assign a dummy empty buffer to channels
Channels are now created with a valid pointer to a buffer before the buffer is allocated. This buffer is a global one called "buf_empty" and of size zero. Thus it prevents any activity from being performed on the buffer and still ensures that chn->buf may always be dereferenced. b_free() also resets the buffer to &buf_empty, and was split into b_drop() which does not reset the buffer.
This commit is contained in:
parent
7dfca9daec
commit
2a4b54359b
@ -40,6 +40,7 @@ struct buffer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern struct pool_head *pool2_buffer;
|
extern struct pool_head *pool2_buffer;
|
||||||
|
extern struct buffer buf_empty;
|
||||||
|
|
||||||
int init_buffer();
|
int init_buffer();
|
||||||
int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len);
|
int buffer_replace2(struct buffer *b, char *pos, char *end, const char *str, int len);
|
||||||
@ -409,13 +410,27 @@ static inline struct buffer *b_alloc(struct buffer **buf)
|
|||||||
return *buf;
|
return *buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Releases buffer *buf.
|
/* Releases buffer *buf (no check of emptiness) */
|
||||||
*/
|
static inline void __b_drop(struct buffer **buf)
|
||||||
static inline void b_free(struct buffer **buf)
|
|
||||||
{
|
{
|
||||||
pool_free2(pool2_buffer, *buf);
|
pool_free2(pool2_buffer, *buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Releases buffer *buf if allocated. */
|
||||||
|
static inline void b_drop(struct buffer **buf)
|
||||||
|
{
|
||||||
|
if (!(*buf)->size)
|
||||||
|
return;
|
||||||
|
__b_drop(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Releases buffer *buf if allocated, and replaces it with &buf_empty. */
|
||||||
|
static inline void b_free(struct buffer **buf)
|
||||||
|
{
|
||||||
|
b_drop(buf);
|
||||||
|
*buf = &buf_empty;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _COMMON_BUFFER_H */
|
#endif /* _COMMON_BUFFER_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -51,6 +51,7 @@ int bo_getblk(struct channel *chn, char *blk, int len, int offset);
|
|||||||
/* Initialize all fields in the channel. */
|
/* Initialize all fields in the channel. */
|
||||||
static inline void channel_init(struct channel *chn)
|
static inline void channel_init(struct channel *chn)
|
||||||
{
|
{
|
||||||
|
chn->buf = &buf_empty;
|
||||||
chn->to_forward = 0;
|
chn->to_forward = 0;
|
||||||
chn->last_read = now_ms;
|
chn->last_read = now_ms;
|
||||||
chn->xfer_small = chn->xfer_large = 0;
|
chn->xfer_small = chn->xfer_large = 0;
|
||||||
|
@ -22,6 +22,10 @@
|
|||||||
|
|
||||||
struct pool_head *pool2_buffer;
|
struct pool_head *pool2_buffer;
|
||||||
|
|
||||||
|
/* this buffer is used to have a valid pointer to an empty buffer in channels
|
||||||
|
* which convey no more data.
|
||||||
|
*/
|
||||||
|
struct buffer buf_empty = { .p = buf_empty.data };
|
||||||
|
|
||||||
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
|
/* perform minimal intializations, report 0 in case of error, 1 if OK. */
|
||||||
int init_buffer()
|
int init_buffer()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user