Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart Pointer Recommendations #795

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/rawsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ rawsock_init(void)
// first entry for the IP address/mask, and gateway, and
// the primary and secondary WINS server for each adapter.

PIP_ADAPTER_INFO pAdapterInfo;
// PIP_ADAPTER_INFO pAdapterInfo;
std::unique_ptr<PIP_ADAPTER_INFO> pAdapterInfo;
PIP_ADAPTER_INFO pAdapter = NULL;
DWORD dwRetVal = 0;
UINT i;
Expand All @@ -112,7 +113,8 @@ rawsock_init(void)
//char buffer[32];

ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof (IP_ADAPTER_INFO));
// pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof (IP_ADAPTER_INFO));
pAdapterInfo = std::make_unique<IP_ADAPTER_INFO>();
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return;
Expand All @@ -121,7 +123,8 @@ rawsock_init(void)
// the necessary size into the ulOutBufLen variable
if (GetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) {
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen);
// pAdapterInfo = (IP_ADAPTER_INFO *) malloc(ulOutBufLen);
pAdapterInfo = std::make_unique<IP_ADAPTER_INFO>(ulOutBufLen);
if (pAdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
return;
Expand Down
2 changes: 2 additions & 0 deletions src/rawsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#define RAWSOCK_H
#include "massip-addr.h"
#include <stdio.h>
#include <iostream>
#include <memory>
struct Adapter;
struct TemplateSet;
#include "stack-queue.h"
Expand Down
2 changes: 2 additions & 0 deletions src/smack.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _SMACK_H
#define _SMACK_H
#include <stdio.h>
#include <iostream>
#include <memory>

#define SMACK_NOT_FOUND ((size_t)(~0))

Expand Down
18 changes: 9 additions & 9 deletions src/smack1.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,9 @@ row_shift_from_symbol_count(unsigned symbol_count)
struct SMACK *
smack_create(const char *name, unsigned nocase)
{
struct SMACK *smack;

smack = (struct SMACK *)malloc(sizeof (struct SMACK));
// struct SMACK *smack;
// smack = (struct SMACK *)malloc(sizeof (struct SMACK));
std::unique_ptr<struct SMACK> smack = std::make_ptr<struct SMACK>();
if (smack == NULL) {
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
Expand All @@ -424,9 +424,9 @@ smack_create(const char *name, unsigned nocase)
static void
create_intermediate_table(struct SMACK *smack, unsigned size)
{
struct SmackRow *x;

x = (struct SmackRow *)malloc(sizeof(*x) * size);
// struct SmackRow *x;
// x = (struct SmackRow *)malloc(sizeof(*x) * size);
std::unique_ptr<struct SmackRow> x = std::make_ptr<struct SmackRow>();
if (x == NULL) {
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
Expand All @@ -452,9 +452,9 @@ destroy_intermediate_table(struct SMACK *smack)
static void
create_matches_table(struct SMACK *smack, unsigned size)
{
struct SmackMatches *x;

x = (struct SmackMatches *)malloc(sizeof(*x) * size);
// struct SmackMatches *x;
// x = (struct SmackMatches *)malloc(sizeof(*x) * size);
std::unique_ptr<struct SmackMatches> x = std::make_ptr<struct SmackMatches>(size);
if (x == NULL) {
fprintf(stderr, "%s: out of memory error\n", "smack");
exit(1);
Expand Down