Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nginx-push-stream-module
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
nginx-push-stream-module
Commits
96424ce2
Commit
96424ce2
authored
Aug 24, 2011
by
Wandenberg Peixoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some points of the code which does not check if alloc memory was done successful
parent
656ea427
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
19 deletions
+54
-19
ngx_http_push_stream_module.c
src/ngx_http_push_stream_module.c
+8
-3
ngx_http_push_stream_module_setup.c
src/ngx_http_push_stream_module_setup.c
+4
-0
ngx_http_push_stream_module_utils.c
src/ngx_http_push_stream_module_utils.c
+42
-16
No files found.
src/ngx_http_push_stream_module.c
View file @
96424ce2
...
...
@@ -160,7 +160,10 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request
len
=
(
subtype
->
format_summarized_worker_item
->
len
>
subtype
->
format_summarized_worker_last_item
->
len
)
?
subtype
->
format_summarized_worker_item
->
len
:
subtype
->
format_summarized_worker_last_item
->
len
;
len
=
used_slots
*
(
2
*
NGX_INT_T_LEN
+
len
-
5
);
//minus 5 sprintf
subscribers_by_workers
=
ngx_pcalloc
(
r
->
pool
,
len
);
if
((
subscribers_by_workers
=
ngx_pcalloc
(
r
->
pool
,
len
))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"Failed to allocate memory to write workers statistics."
);
return
NGX_HTTP_INTERNAL_SERVER_ERROR
;
}
ngx_memset
(
subscribers_by_workers
,
'\0'
,
len
);
start
=
subscribers_by_workers
;
for
(
i
=
0
,
j
=
0
;
(
i
<
used_slots
)
&&
(
j
<
NGX_MAX_PROCESSES
);
j
++
)
{
...
...
@@ -253,8 +256,10 @@ ngx_http_push_stream_send_response_all_channels_info_detailed(ngx_http_request_t
}
format
=
(
next
!=
&
queue_channel_info
)
?
subtype
->
format_group_item
:
subtype
->
format_group_last_item
;
chain
->
buf
=
ngx_http_push_stream_channel_info_formatted
(
r
->
pool
,
format
,
&
channel_info
->
id
,
channel_info
->
published_messages
,
channel_info
->
stored_messages
,
channel_info
->
subscribers
);
if
((
chain
->
buf
=
ngx_http_push_stream_channel_info_formatted
(
r
->
pool
,
format
,
&
channel_info
->
id
,
channel_info
->
published_messages
,
channel_info
->
stored_messages
,
channel_info
->
subscribers
))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
r
->
connection
->
log
,
0
,
"push stream module: unable to allocate memory to format channel info"
);
return
NGX_HTTP_INTERNAL_SERVER_ERROR
;
}
chain
->
buf
->
last_buf
=
0
;
content_len
+=
ngx_buf_size
(
chain
->
buf
);
...
...
src/ngx_http_push_stream_module_setup.c
View file @
96424ce2
...
...
@@ -502,6 +502,10 @@ ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
// append crlf to templates
if
(
conf
->
header_template
.
len
>
0
)
{
ngx_str_t
*
aux
=
ngx_http_push_stream_get_formatted_chunk
(
conf
->
header_template
.
data
,
conf
->
header_template
.
len
,
cf
->
pool
);
if
(
aux
==
NULL
)
{
ngx_conf_log_error
(
NGX_LOG_ERR
,
cf
,
0
,
"push stream module: unable to allocate memory to format header template"
);
return
NGX_CONF_ERROR
;
}
conf
->
header_template
.
data
=
aux
->
data
;
conf
->
header_template
.
len
=
aux
->
len
;
}
...
...
src/ngx_http_push_stream_module_utils.c
View file @
96424ce2
...
...
@@ -142,21 +142,18 @@ ngx_http_push_stream_convert_char_to_msg_on_shared_locked(u_char *data, size_t l
ngx_http_push_stream_msg_t
*
msg
;
int
i
=
0
;
msg
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_http_push_stream_msg_t
));
if
(
msg
==
NULL
)
{
if
((
msg
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_http_push_stream_msg_t
)))
==
NULL
)
{
return
NULL
;
}
msg
->
formatted_messages
=
NULL
;
msg
->
buf
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_buf_t
));
if
(
msg
->
buf
==
NULL
)
{
if
((
msg
->
buf
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_buf_t
)))
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
msg
->
buf
->
start
=
ngx_slab_alloc_locked
(
shpool
,
len
+
1
);
if
(
msg
->
buf
->
start
==
NULL
)
{
if
((
msg
->
buf
->
start
=
ngx_slab_alloc_locked
(
shpool
,
len
+
1
))
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
...
...
@@ -177,14 +174,20 @@ ngx_http_push_stream_convert_char_to_msg_on_shared_locked(u_char *data, size_t l
msg
->
raw
.
data
=
msg
->
buf
->
start
;
msg
->
raw
.
len
=
len
;
msg
->
formatted_messages
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_str_t
)
*
ngx_http_push_stream_module_main_conf
->
qtd_templates
);
if
((
msg
->
formatted_messages
=
ngx_slab_alloc_locked
(
shpool
,
sizeof
(
ngx_str_t
)
*
ngx_http_push_stream_module_main_conf
->
qtd_templates
))
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
while
((
cur
=
(
ngx_http_push_stream_template_queue_t
*
)
ngx_queue_next
(
&
cur
->
queue
))
!=
sentinel
)
{
ngx_str_t
*
aux
=
ngx_http_push_stream_format_message
(
channel
,
msg
,
cur
->
template
,
temp_pool
);
if
(
aux
==
NULL
)
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
ngx_str_t
*
chunk
=
ngx_http_push_stream_get_formatted_chunk
(
aux
->
data
,
aux
->
len
,
temp_pool
);
ngx_str_t
*
formmated
=
(
msg
->
formatted_messages
+
i
);
formmated
->
data
=
ngx_slab_alloc_locked
(
shpool
,
chunk
->
len
+
1
);
if
(
formmated
->
data
==
NULL
)
{
if
((
chunk
==
NULL
)
||
((
formmated
->
data
=
ngx_slab_alloc_locked
(
shpool
,
chunk
->
len
+
1
))
==
NULL
))
{
ngx_http_push_stream_free_message_memory_locked
(
shpool
,
msg
);
return
NULL
;
}
...
...
@@ -317,7 +320,11 @@ ngx_http_push_stream_delete_channel(ngx_str_t *id, ngx_pool_t *temp_pool) {
ngx_http_push_stream_ensure_qtd_of_messages_locked
(
channel
,
0
,
0
);
// apply channel deleted message text to message template
channel
->
channel_deleted_message
=
ngx_http_push_stream_convert_char_to_msg_on_shared_locked
(
ngx_http_push_stream_module_main_conf
->
channel_deleted_message_text
.
data
,
ngx_http_push_stream_module_main_conf
->
channel_deleted_message_text
.
len
,
channel
,
NGX_HTTP_PUSH_STREAM_CHANNEL_DELETED_MESSAGE_ID
,
temp_pool
);
if
((
channel
->
channel_deleted_message
=
ngx_http_push_stream_convert_char_to_msg_on_shared_locked
(
ngx_http_push_stream_module_main_conf
->
channel_deleted_message_text
.
data
,
ngx_http_push_stream_module_main_conf
->
channel_deleted_message_text
.
len
,
channel
,
NGX_HTTP_PUSH_STREAM_CHANNEL_DELETED_MESSAGE_ID
,
temp_pool
))
==
NULL
)
{
ngx_shmtx_unlock
(
&
(
shpool
)
->
mutex
);
ngx_log_error
(
NGX_LOG_ERR
,
temp_pool
->
log
,
0
,
"push stream module: unable to allocate memory to channel deleted message"
);
return
;
}
// send signal to each worker with subscriber to this channel
cur
=
&
channel
->
workers_with_subscribers
;
...
...
@@ -663,6 +670,10 @@ ngx_http_push_stream_buffer_timer_wake_handler(ngx_event_t *ev)
static
u_char
*
ngx_http_push_stream_str_replace
(
u_char
*
org
,
u_char
*
find
,
u_char
*
replace
,
ngx_uint_t
offset
,
ngx_pool_t
*
pool
)
{
if
(
org
==
NULL
)
{
return
NULL
;
}
ngx_uint_t
len_org
=
ngx_strlen
(
org
);
ngx_uint_t
len_find
=
ngx_strlen
(
find
);
ngx_uint_t
len_replace
=
ngx_strlen
(
replace
);
...
...
@@ -670,9 +681,14 @@ ngx_http_push_stream_str_replace(u_char *org, u_char *find, u_char *replace, ngx
u_char
*
result
=
org
;
if
(
len_find
>
0
)
{
u_char
*
ret
=
(
u_char
*
)
ngx_strstr
(
org
+
offset
,
find
);
u_char
*
ret
=
(
u_char
*
)
ngx_strstr
(
org
+
offset
,
find
);
if
(
ret
!=
NULL
)
{
u_char
*
tmp
=
ngx_pcalloc
(
pool
,
len_org
+
len_replace
+
len_find
+
1
);
u_char
*
tmp
=
ngx_pcalloc
(
pool
,
len_org
+
len_replace
+
len_find
+
1
);
if
(
tmp
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to apply text replace"
);
return
NULL
;
}
ngx_memset
(
tmp
,
'\0'
,
len_org
+
len_replace
+
len_find
+
1
);
u_int
len_found
=
ret
-
org
;
...
...
@@ -722,7 +738,10 @@ ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx
if
(
message
!=
NULL
)
{
message_id
=
message
->
id
;
len
=
ngx_buf_size
(
message
->
buf
);
msg
=
ngx_pcalloc
(
pool
,
len
+
1
);
if
((
msg
=
ngx_pcalloc
(
pool
,
len
+
1
))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to copy message text"
);
return
NULL
;
}
ngx_memset
(
msg
,
'\0'
,
len
+
1
);
ngx_memcpy
(
msg
,
message
->
buf
->
pos
,
len
);
}
...
...
@@ -733,10 +752,17 @@ ngx_http_push_stream_format_message(ngx_http_push_stream_channel_t *channel, ngx
txt
=
ngx_http_push_stream_str_replace
(
txt
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_CHANNEL
.
data
,
channel_id
,
0
,
pool
);
txt
=
ngx_http_push_stream_str_replace
(
txt
,
NGX_HTTP_PUSH_STREAM_TOKEN_MESSAGE_TEXT
.
data
,
msg
,
0
,
pool
);
len
=
ngx_strlen
(
txt
);
str
=
ngx_pcalloc
(
pool
,
sizeof
(
ngx_str_t
));
if
(
txt
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to replace message values on template"
);
return
NULL
;
}
if
((
str
=
ngx_pcalloc
(
pool
,
sizeof
(
ngx_str_t
)))
==
NULL
)
{
ngx_log_error
(
NGX_LOG_ERR
,
pool
->
log
,
0
,
"push stream module: unable to allocate memory to return message applied to template"
);
return
NULL
;
}
str
->
data
=
txt
;
str
->
len
=
len
;
str
->
len
=
ngx_strlen
(
txt
)
;
return
str
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment